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 @@ -128,7 +128,11 @@ class found there. (This assumes classes don't modify their
128128 continue
129129 # mangled names
130130 elif name .startswith ('__' ) and not name .endswith ('__' ):
131- names .append ('_%s%s' % (c .__name__ , name ))
131+ stripped = c .__name__ .lstrip ('_' )
132+ if stripped :
133+ names .append ('_%s%s' % (stripped , name ))
134+ else :
135+ names .append (name )
132136 else :
133137 names .append (name )
134138
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ class WithWeakref(object):
1616class WithPrivate (object ):
1717 __slots__ = ('__spam' ,)
1818
19+ class _WithLeadingUnderscoreAndPrivate (object ):
20+ __slots__ = ('__spam' ,)
21+
22+ class ___ (object ):
23+ __slots__ = ('__spam' ,)
24+
1925class WithSingleString (object ):
2026 __slots__ = 'spam'
2127
@@ -104,6 +110,10 @@ def test_slotnames(self):
104110 self .assertEqual (copyreg ._slotnames (WithWeakref ), [])
105111 expected = ['_WithPrivate__spam' ]
106112 self .assertEqual (copyreg ._slotnames (WithPrivate ), expected )
113+ expected = ['_WithLeadingUnderscoreAndPrivate__spam' ]
114+ self .assertEqual (copyreg ._slotnames (_WithLeadingUnderscoreAndPrivate ),
115+ expected )
116+ self .assertEqual (copyreg ._slotnames (___ ), ['__spam' ])
107117 self .assertEqual (copyreg ._slotnames (WithSingleString ), ['spam' ])
108118 expected = ['eggs' , 'spam' ]
109119 expected .sort ()
Original file line number Diff line number Diff line change @@ -598,6 +598,7 @@ David Harrigan
598598Brian Harring
599599Jonathan Hartley
600600Travis B. Hartwell
601+ Shane Harvey
601602Larry Hastings
602603Tim Hatch
603604Shane Hathaway
Original file line number Diff line number Diff line change 1+ Fix `copyreg._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