Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-79512: Fixed names and __module__ value of weakref classes #93719

Merged
merged 1 commit into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-79512: Fixed names and __module__ value of weakref classes
Classes ReferenceType, ProxyType and CallableProxyType have now correct
atrtributes __module__, __name__ and __qualname__. It makes them pickleable.
  • Loading branch information
serhiy-storchaka committed Jun 11, 2022
commit 9c04de88e56dc3407ec96cf6af0bd41939b858e8
11 changes: 11 additions & 0 deletions Lib/test/test_weakref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,17 @@ def test_atexit(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -754,7 +754,7 @@ _PyWeakref_ProxyType = {
PyTypeObject
_PyWeakref_CallableProxyType = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"weakcallableproxy",
"weakref.CallableProxyType",
sizeof(PyWeakReference),
0,
/* methods */
Expand Down