mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #24097: Fixed crash in object.__reduce__() if slot name is freed inside
__getattr__. Original patch by Antoine Pitrou.
This commit is contained in:
commit
6a50e79130
3 changed files with 23 additions and 0 deletions
|
@ -5085,6 +5085,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):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue