summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-25 16:33:29 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-25 16:33:29 (GMT)
commitd28bb624d120466ba5ebdf5063286b2f309283ab (patch)
treefa51e9e30f4f0cc80d72a3f0d9184e42afdbfde9 /Lib
parent33e7ea5ad6a3027ef684ac7941fccf7c97d5cbd6 (diff)
downloadcpython-d28bb624d120466ba5ebdf5063286b2f309283ab.zip
cpython-d28bb624d120466ba5ebdf5063286b2f309283ab.tar.gz
cpython-d28bb624d120466ba5ebdf5063286b2f309283ab.tar.bz2
Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__. Original patch by Antoine Pitrou.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_descr.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index ce9626c..64a4a36 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4988,6 +4988,23 @@ class PicklingTests(unittest.TestCase):
objcopy2 = deepcopy(objcopy)
self._assert_is_copy(obj, objcopy2)
+ def test_issue24097(self):
+ # Slot name is freed inside __getattr__ and is later used.
+ class S(str): # Not interned
+ pass
+ class A:
+ __slotnames__ = [S('spam')]
+ def __getattr__(self, attr):
+ if attr == 'spam':
+ A.__slotnames__[:] = [S('spam')]
+ return 42
+ else:
+ raise AttributeError
+
+ import copyreg
+ expected = (copyreg.__newobj__, (A,), (None, {'spam': 42}), None, None)
+ self.assertEqual(A().__reduce__(2), expected) # Shouldn't crash
+
class SharedKeyTests(unittest.TestCase):