Skip to content
Permalink
Browse files

[2.7] bpo-31107: Fix copyreg mangled slot names calculation. (GH-2989)…

…. (#3004)

(cherry picked from commit c4c9866)
  • Loading branch information
ShaneHarvey authored and serhiy-storchaka committed Aug 5, 2017
1 parent 5fbb8e3 commit 88ffff5ddbb8692ecb2c661aa29000dbde9eff8c
Showing with 18 additions and 1 deletion.
  1. +5 −1 Lib/copy_reg.py
  2. +10 −0 Lib/test/test_copy_reg.py
  3. +1 −0 Misc/ACKS
  4. +2 −0 Misc/NEWS.d/next/Library/2017-08-02-12-48-15.bpo-31107.1t2hn5.rst
@@ -127,7 +127,11 @@ class found there. (This assumes classes don't modify their
continue
# mangled names
elif name.startswith('__') and not name.endswith('__'):
names.append('_%s%s' % (c.__name__, name))
stripped = c.__name__.lstrip('_')
if stripped:
names.append('_%s%s' % (stripped, name))
else:
names.append(name)
else:
names.append(name)

@@ -17,6 +17,12 @@ class WithWeakref(object):
class WithPrivate(object):
__slots__ = ('__spam',)

class _WithLeadingUnderscoreAndPrivate(object):
__slots__ = ('__spam',)

class ___(object):
__slots__ = ('__spam',)

class WithSingleString(object):
__slots__ = 'spam'

@@ -105,6 +111,10 @@ def test_slotnames(self):
self.assertEqual(copy_reg._slotnames(WithWeakref), [])
expected = ['_WithPrivate__spam']
self.assertEqual(copy_reg._slotnames(WithPrivate), expected)
expected = ['_WithLeadingUnderscoreAndPrivate__spam']
self.assertEqual(copy_reg._slotnames(_WithLeadingUnderscoreAndPrivate),
expected)
self.assertEqual(copy_reg._slotnames(___), ['__spam'])
self.assertEqual(copy_reg._slotnames(WithSingleString), ['spam'])
expected = ['eggs', 'spam']
expected.sort()
@@ -543,6 +543,7 @@ David Harrigan
Brian Harring
Jonathan Hartley
Travis B. Hartwell
Shane Harvey
Larry Hastings
Tim Hatch
Shane Hathaway
@@ -0,0 +1,2 @@
Fix `copy_reg._slotnames()` mangled attribute calculation for classes whose
name begins with an underscore. Patch by Shane Harvey.

0 comments on commit 88ffff5

Please sign in to comment.
You can’t perform that action at this time.