File tree Expand file tree Collapse file tree 4 files changed +18
-1
lines changed Expand file tree Collapse file tree 4 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -127,7 +127,11 @@ class found there. (This assumes classes don't modify their
127127 continue
128128 # mangled names
129129 elif name .startswith ('__' ) and not name .endswith ('__' ):
130- names .append ('_%s%s' % (c .__name__ , name ))
130+ stripped = c .__name__ .lstrip ('_' )
131+ if stripped :
132+ names .append ('_%s%s' % (stripped , name ))
133+ else :
134+ names .append (name )
131135 else :
132136 names .append (name )
133137
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ class WithWeakref(object):
1717class WithPrivate (object ):
1818 __slots__ = ('__spam' ,)
1919
20+ class _WithLeadingUnderscoreAndPrivate (object ):
21+ __slots__ = ('__spam' ,)
22+
23+ class ___ (object ):
24+ __slots__ = ('__spam' ,)
25+
2026class WithSingleString (object ):
2127 __slots__ = 'spam'
2228
@@ -105,6 +111,10 @@ def test_slotnames(self):
105111 self .assertEqual (copy_reg ._slotnames (WithWeakref ), [])
106112 expected = ['_WithPrivate__spam' ]
107113 self .assertEqual (copy_reg ._slotnames (WithPrivate ), expected )
114+ expected = ['_WithLeadingUnderscoreAndPrivate__spam' ]
115+ self .assertEqual (copy_reg ._slotnames (_WithLeadingUnderscoreAndPrivate ),
116+ expected )
117+ self .assertEqual (copy_reg ._slotnames (___ ), ['__spam' ])
108118 self .assertEqual (copy_reg ._slotnames (WithSingleString ), ['spam' ])
109119 expected = ['eggs' , 'spam' ]
110120 expected .sort ()
Original file line number Diff line number Diff line change @@ -543,6 +543,7 @@ David Harrigan
543543Brian Harring
544544Jonathan Hartley
545545Travis B. Hartwell
546+ Shane Harvey
546547Larry Hastings
547548Tim Hatch
548549Shane Hathaway
Original file line number Diff line number Diff line change 1+ Fix `copy_reg._slotnames() ` mangled attribute calculation for classes whose
2+ name begins with an underscore. Patch by Shane Harvey.
You can’t perform that action at this time.
0 commit comments