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
127
127
continue
128
128
# mangled names
129
129
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 )
131
135
else :
132
136
names .append (name )
133
137
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ class WithWeakref(object):
17
17
class WithPrivate (object ):
18
18
__slots__ = ('__spam' ,)
19
19
20
+ class _WithLeadingUnderscoreAndPrivate (object ):
21
+ __slots__ = ('__spam' ,)
22
+
23
+ class ___ (object ):
24
+ __slots__ = ('__spam' ,)
25
+
20
26
class WithSingleString (object ):
21
27
__slots__ = 'spam'
22
28
@@ -105,6 +111,10 @@ def test_slotnames(self):
105
111
self .assertEqual (copy_reg ._slotnames (WithWeakref ), [])
106
112
expected = ['_WithPrivate__spam' ]
107
113
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' ])
108
118
self .assertEqual (copy_reg ._slotnames (WithSingleString ), ['spam' ])
109
119
expected = ['eggs' , 'spam' ]
110
120
expected .sort ()
Original file line number Diff line number Diff line change @@ -543,6 +543,7 @@ David Harrigan
543
543
Brian Harring
544
544
Jonathan Hartley
545
545
Travis B. Hartwell
546
+ Shane Harvey
546
547
Larry Hastings
547
548
Tim Hatch
548
549
Shane 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