summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-11-25 16:35:33 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-11-25 16:35:33 (GMT)
commitee1b24ccaaab4efd583f30a27957ed9fdf374e2e (patch)
tree8bca87b8ae5e503eef40631f22e7b37256e3af79 /Lib
parent282e831a5a851df2b66da2e4902ad64cbe035930 (diff)
downloadcpython-ee1b24ccaaab4efd583f30a27957ed9fdf374e2e.zip
cpython-ee1b24ccaaab4efd583f30a27957ed9fdf374e2e.tar.gz
cpython-ee1b24ccaaab4efd583f30a27957ed9fdf374e2e.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.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 25f65c5..0861bcc 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4763,6 +4763,26 @@ class PTypesLongInitTest(unittest.TestCase):
type.mro(tuple)
+class PicklingTests(unittest.TestCase):
+
+ def test_issue24097(self):
+ # Slot name is freed inside __getattr__ and is later used.
+ class S(str): # Not interned
+ pass
+ class A(object):
+ __slotnames__ = [S('spam')]
+ def __getattr__(self, attr):
+ if attr == 'spam':
+ A.__slotnames__[:] = [S('spam')]
+ return 42
+ else:
+ raise AttributeError
+
+ import copy_reg
+ expected = (copy_reg.__newobj__, (A,), ({}, {'spam': 42}), None, None)
+ self.assertEqual(A().__reduce__(2), expected)
+
+
def test_main():
deprecations = [(r'complex divmod\(\), // and % are deprecated$',
DeprecationWarning)]
@@ -4774,7 +4794,8 @@ def test_main():
with test_support.check_warnings(*deprecations):
# Run all local test cases, with PTypesLongInitTest first.
test_support.run_unittest(PTypesLongInitTest, OperatorsTest,
- ClassPropertiesAndMethods, DictProxyTests)
+ ClassPropertiesAndMethods, DictProxyTests,
+ PicklingTests)
if __name__ == "__main__":
test_main()