gh-82951: Fix serializing by name in pickle protocols < 4 (GH-122149)

Serializing objects with complex __qualname__ (such as unbound methods and
nested classes) by name no longer involves serializing parent objects by value
in pickle protocols < 4.
This commit is contained in:
Serhiy Storchaka 2024-07-25 11:45:19 +03:00 committed by GitHub
parent ca0f7c447c
commit dc07f65a53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 82 additions and 26 deletions

View file

@ -2818,6 +2818,18 @@ class AbstractPickleTests:
self.assertIs(unpickled, Recursive)
del Recursive.mod # break reference loop
def test_recursive_nested_names2(self):
global Recursive
class Recursive:
pass
Recursive.ref = Recursive
Recursive.__qualname__ = 'Recursive.ref'
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
unpickled = self.loads(self.dumps(Recursive, proto))
self.assertIs(unpickled, Recursive)
del Recursive.ref # break reference loop
def test_py_methods(self):
global PyMethodsTest
class PyMethodsTest: