mirror of
https://github.com/python/cpython.git
synced 2025-11-08 17:41:42 +00:00
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.
This commit is contained in:
parent
6fd4c8ec77
commit
8352e322e8
3 changed files with 17 additions and 3 deletions
|
|
@ -2154,6 +2154,17 @@ def test_atexit(self):
|
||||||
self.assertTrue(b'ZeroDivisionError' in err)
|
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
|
libreftest = """ Doctest for examples in the library reference: weakref.rst
|
||||||
|
|
||||||
>>> from test.support import gc_collect
|
>>> from test.support import gc_collect
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
@ -371,7 +371,7 @@ static PyMethodDef weakref_methods[] = {
|
||||||
PyTypeObject
|
PyTypeObject
|
||||||
_PyWeakref_RefType = {
|
_PyWeakref_RefType = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
.tp_name = "weakref",
|
.tp_name = "weakref.ReferenceType",
|
||||||
.tp_basicsize = sizeof(PyWeakReference),
|
.tp_basicsize = sizeof(PyWeakReference),
|
||||||
.tp_dealloc = weakref_dealloc,
|
.tp_dealloc = weakref_dealloc,
|
||||||
.tp_vectorcall_offset = offsetof(PyWeakReference, vectorcall),
|
.tp_vectorcall_offset = offsetof(PyWeakReference, vectorcall),
|
||||||
|
|
@ -719,7 +719,7 @@ static PyMappingMethods proxy_as_mapping = {
|
||||||
PyTypeObject
|
PyTypeObject
|
||||||
_PyWeakref_ProxyType = {
|
_PyWeakref_ProxyType = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
"weakproxy",
|
"weakref.ProxyType",
|
||||||
sizeof(PyWeakReference),
|
sizeof(PyWeakReference),
|
||||||
0,
|
0,
|
||||||
/* methods */
|
/* methods */
|
||||||
|
|
@ -754,7 +754,7 @@ _PyWeakref_ProxyType = {
|
||||||
PyTypeObject
|
PyTypeObject
|
||||||
_PyWeakref_CallableProxyType = {
|
_PyWeakref_CallableProxyType = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
"weakcallableproxy",
|
"weakref.CallableProxyType",
|
||||||
sizeof(PyWeakReference),
|
sizeof(PyWeakReference),
|
||||||
0,
|
0,
|
||||||
/* methods */
|
/* methods */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue