]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-79512: Fixed names and __module__ value of weakref classes (GH-93719) ...
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 21 Jun 2022 19:36:09 +0000 (22:36 +0300)
committerGitHub <noreply@github.com>
Tue, 21 Jun 2022 19:36:09 +0000 (22:36 +0300)
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>
Lib/test/test_weakref.py
Misc/NEWS.d/next/Library/2022-06-11-13-32-17.gh-issue-79512.A1KTDr.rst [new file with mode: 0644]
Objects/weakrefobject.c

index 096833d1ebb355b7a6193d15bd88e0dab0a0e9b0..f612e79dca1818e877ce7c7c900ef8755da57a1a 100644 (file)
@@ -2145,6 +2145,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 (file)
index 0000000..5393fb5
--- /dev/null
@@ -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.
index bb56c7dbdb8322915f1da039a9fe933124c3bc3d..cfb8ba322ae37a06bd7afeb0b60a7b3685cd4193 100644 (file)
@@ -371,7 +371,7 @@ static PyMethodDef weakref_methods[] = {
 PyTypeObject
 _PyWeakref_RefType = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "weakref",
+    "weakref.ReferenceType",
     sizeof(PyWeakReference),
     0,
     weakref_dealloc,            /*tp_dealloc*/
@@ -741,7 +741,7 @@ static PyMappingMethods proxy_as_mapping = {
 PyTypeObject
 _PyWeakref_ProxyType = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "weakproxy",
+    "weakref.ProxyType",
     sizeof(PyWeakReference),
     0,
     /* methods */
@@ -776,7 +776,7 @@ _PyWeakref_ProxyType = {
 PyTypeObject
 _PyWeakref_CallableProxyType = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "weakcallableproxy",
+    "weakref.CallableProxyType",
     sizeof(PyWeakReference),
     0,
     /* methods */