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

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.
(cherry picked from commit dc07f65a53)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-07-25 12:44:55 +02:00 committed by GitHub
parent 977c799286
commit 984f8aaa2f
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: