Skip to content

Commit 54250e7

Browse files
[3.10] gh-79512: Fixed names and __module__ value of weakref classes (GH-93719) (GH-94071)
Classes ReferenceType, ProxyType and CallableProxyType have now correct atrtributes __module__, __name__ and __qualname__. It makes them (types, not instances) pickleable. (cherry picked from commit 8352e32) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 46d0e1c commit 54250e7

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Lib/test/test_weakref.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,17 @@ def test_atexit(self):
21452145
self.assertTrue(b'ZeroDivisionError' in err)
21462146

21472147

2148+
class ModuleTestCase(unittest.TestCase):
2149+
def test_names(self):
2150+
for name in ('ReferenceType', 'ProxyType', 'CallableProxyType',
2151+
'WeakMethod', 'WeakSet', 'WeakKeyDictionary', 'WeakValueDictionary'):
2152+
obj = getattr(weakref, name)
2153+
if name != 'WeakSet':
2154+
self.assertEqual(obj.__module__, 'weakref')
2155+
self.assertEqual(obj.__name__, name)
2156+
self.assertEqual(obj.__qualname__, name)
2157+
2158+
21482159
libreftest = """ Doctest for examples in the library reference: weakref.rst
21492160
21502161
>>> from test.support import gc_collect
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed names and ``__module__`` value of :mod:`weakref` classes
2+
:class:`~weakref.ReferenceType`, :class:`~weakref.ProxyType`,
3+
:class:`~weakref.CallableProxyType`. It makes them pickleable.

Objects/weakrefobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static PyMethodDef weakref_methods[] = {
371371
PyTypeObject
372372
_PyWeakref_RefType = {
373373
PyVarObject_HEAD_INIT(&PyType_Type, 0)
374-
"weakref",
374+
"weakref.ReferenceType",
375375
sizeof(PyWeakReference),
376376
0,
377377
weakref_dealloc, /*tp_dealloc*/
@@ -741,7 +741,7 @@ static PyMappingMethods proxy_as_mapping = {
741741
PyTypeObject
742742
_PyWeakref_ProxyType = {
743743
PyVarObject_HEAD_INIT(&PyType_Type, 0)
744-
"weakproxy",
744+
"weakref.ProxyType",
745745
sizeof(PyWeakReference),
746746
0,
747747
/* methods */
@@ -776,7 +776,7 @@ _PyWeakref_ProxyType = {
776776
PyTypeObject
777777
_PyWeakref_CallableProxyType = {
778778
PyVarObject_HEAD_INIT(&PyType_Type, 0)
779-
"weakcallableproxy",
779+
"weakref.CallableProxyType",
780780
sizeof(PyWeakReference),
781781
0,
782782
/* methods */

0 commit comments

Comments
 (0)