Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8352e32

Browse files
gh-79512: Fixed names and __module__ value of weakref classes (GH-93719)
Classes ReferenceType, ProxyType and CallableProxyType have now correctatrtributes __module__, __name__ and __qualname__.It makes them (types, not instances) pickleable.
1 parent6fd4c8e commit8352e32

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
@@ -2154,6 +2154,17 @@ def test_atexit(self):
21542154
self.assertTrue(b'ZeroDivisionError'inerr)
21552155

21562156

2157+
classModuleTestCase(unittest.TestCase):
2158+
deftest_names(self):
2159+
fornamein ('ReferenceType','ProxyType','CallableProxyType',
2160+
'WeakMethod','WeakSet','WeakKeyDictionary','WeakValueDictionary'):
2161+
obj=getattr(weakref,name)
2162+
ifname!='WeakSet':
2163+
self.assertEqual(obj.__module__,'weakref')
2164+
self.assertEqual(obj.__name__,name)
2165+
self.assertEqual(obj.__qualname__,name)
2166+
2167+
21572168
libreftest=""" Doctest for examples in the library reference: weakref.rst
21582169
21592170
>>> 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-
.tp_name="weakref",
374+
.tp_name="weakref.ReferenceType",
375375
.tp_basicsize=sizeof(PyWeakReference),
376376
.tp_dealloc=weakref_dealloc,
377377
.tp_vectorcall_offset= offsetof(PyWeakReference,vectorcall),
@@ -719,7 +719,7 @@ static PyMappingMethods proxy_as_mapping = {
719719
PyTypeObject
720720
_PyWeakref_ProxyType= {
721721
PyVarObject_HEAD_INIT(&PyType_Type,0)
722-
"weakproxy",
722+
"weakref.ProxyType",
723723
sizeof(PyWeakReference),
724724
0,
725725
/* methods */
@@ -754,7 +754,7 @@ _PyWeakref_ProxyType = {
754754
PyTypeObject
755755
_PyWeakref_CallableProxyType= {
756756
PyVarObject_HEAD_INIT(&PyType_Type,0)
757-
"weakcallableproxy",
757+
"weakref.CallableProxyType",
758758
sizeof(PyWeakReference),
759759
0,
760760
/* methods */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp