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
128
128
continue
129
129
# mangled names
130
130
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 )
132
136
else :
133
137
names .append (name )
134
138
Original file line number Diff line number Diff line change @@ -16,6 +16,12 @@ class WithWeakref(object):
16
16
class WithPrivate (object ):
17
17
__slots__ = ('__spam' ,)
18
18
19
+ class _WithLeadingUnderscoreAndPrivate (object ):
20
+ __slots__ = ('__spam' ,)
21
+
22
+ class ___ (object ):
23
+ __slots__ = ('__spam' ,)
24
+
19
25
class WithSingleString (object ):
20
26
__slots__ = 'spam'
21
27
@@ -104,6 +110,10 @@ def test_slotnames(self):
104
110
self .assertEqual (copyreg ._slotnames (WithWeakref ), [])
105
111
expected = ['_WithPrivate__spam' ]
106
112
self .assertEqual (copyreg ._slotnames (WithPrivate ), expected )
113
+ expected = ['_WithLeadingUnderscoreAndPrivate__spam' ]
114
+ self .assertEqual (copyreg ._slotnames (_WithLeadingUnderscoreAndPrivate ),
115
+ expected )
116
+ self .assertEqual (copyreg ._slotnames (___ ), ['__spam' ])
107
117
self .assertEqual (copyreg ._slotnames (WithSingleString ), ['spam' ])
108
118
expected = ['eggs' , 'spam' ]
109
119
expected .sort ()
Original file line number Diff line number Diff line change @@ -592,6 +592,7 @@ David Harrigan
592
592
Brian Harring
593
593
Jonathan Hartley
594
594
Travis B. Hartwell
595
+ Shane Harvey
595
596
Larry Hastings
596
597
Tim Hatch
597
598
Shane 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