diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-06-14 19:12:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 19:12:51 (GMT) |
commit | 29c7e815bc6087bfa0f34855d8313b16f236dd34 (patch) | |
tree | 43f5d86415ed505ee379ec12431979c4665aa922 | |
parent | 8dc5df4e21964ec746634cd19d4ffe60acf5e0f6 (diff) | |
download | cpython-29c7e815bc6087bfa0f34855d8313b16f236dd34.zip cpython-29c7e815bc6087bfa0f34855d8313b16f236dd34.tar.gz cpython-29c7e815bc6087bfa0f34855d8313b16f236dd34.tar.bz2 |
gh-79512: Fixed names and __module__ value of weakref classes (GH-93719)
Classes ReferenceType, ProxyType and CallableProxyType have now correct
atrtributes __module__, __name__ and __qualname__.
It makes them (types, not instances) pickleable.
(cherry picked from commit 8352e322e87ba39c71e578b65ad8ae156ca3e0c7)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r-- | Lib/test/test_weakref.py | 11 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-06-11-13-32-17.gh-issue-79512.A1KTDr.rst | 3 | ||||
-rw-r--r-- | Objects/weakrefobject.c | 6 |
3 files changed, 17 insertions, 3 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py index 702bb44..3a9573d 100644 --- a/Lib/test/test_weakref.py +++ b/Lib/test/test_weakref.py @@ -2154,6 +2154,17 @@ class FinalizeTestCase(unittest.TestCase): self.assertTrue(b'ZeroDivisionError' in err) +class ModuleTestCase(unittest.TestCase): + def test_names(self): + for name in ('ReferenceType', 'ProxyType', 'CallableProxyType', + 'WeakMethod', 'WeakSet', 'WeakKeyDictionary', 'WeakValueDictionary'): + obj = getattr(weakref, name) + if name != 'WeakSet': + self.assertEqual(obj.__module__, 'weakref') + self.assertEqual(obj.__name__, name) + self.assertEqual(obj.__qualname__, name) + + libreftest = """ Doctest for examples in the library reference: weakref.rst >>> from test.support import gc_collect diff --git a/Misc/NEWS.d/next/Library/2022-06-11-13-32-17.gh-issue-79512.A1KTDr.rst b/Misc/NEWS.d/next/Library/2022-06-11-13-32-17.gh-issue-79512.A1KTDr.rst new file mode 100644 index 0000000..5393fb5 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-06-11-13-32-17.gh-issue-79512.A1KTDr.rst @@ -0,0 +1,3 @@ +Fixed names and ``__module__`` value of :mod:`weakref` classes +:class:`~weakref.ReferenceType`, :class:`~weakref.ProxyType`, +:class:`~weakref.CallableProxyType`. It makes them pickleable. diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 1712533..2b4361e 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -371,7 +371,7 @@ static PyMethodDef weakref_methods[] = { PyTypeObject _PyWeakref_RefType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - .tp_name = "weakref", + .tp_name = "weakref.ReferenceType", .tp_basicsize = sizeof(PyWeakReference), .tp_dealloc = weakref_dealloc, .tp_vectorcall_offset = offsetof(PyWeakReference, vectorcall), @@ -719,7 +719,7 @@ static PyMappingMethods proxy_as_mapping = { PyTypeObject _PyWeakref_ProxyType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "weakproxy", + "weakref.ProxyType", sizeof(PyWeakReference), 0, /* methods */ @@ -754,7 +754,7 @@ _PyWeakref_ProxyType = { PyTypeObject _PyWeakref_CallableProxyType = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "weakcallableproxy", + "weakref.CallableProxyType", sizeof(PyWeakReference), 0, /* methods */ |