bpo-39481: Make weakref and WeakSet generic (GH-19497)
This commit is contained in:
parent
cecf049673
commit
8ef875028a
|
@ -3,6 +3,7 @@
|
||||||
# by abc.py to load everything else at startup.
|
# by abc.py to load everything else at startup.
|
||||||
|
|
||||||
from _weakref import ref
|
from _weakref import ref
|
||||||
|
from types import GenericAlias
|
||||||
|
|
||||||
__all__ = ['WeakSet']
|
__all__ = ['WeakSet']
|
||||||
|
|
||||||
|
@ -197,3 +198,5 @@ class WeakSet:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return repr(self.data)
|
return repr(self.data)
|
||||||
|
|
||||||
|
__class_getitem__ = classmethod(GenericAlias)
|
||||||
|
|
|
@ -33,6 +33,7 @@ from tempfile import TemporaryDirectory, SpooledTemporaryFile
|
||||||
from urllib.parse import SplitResult, ParseResult
|
from urllib.parse import SplitResult, ParseResult
|
||||||
from unittest.case import _AssertRaisesContext
|
from unittest.case import _AssertRaisesContext
|
||||||
from queue import Queue, SimpleQueue
|
from queue import Queue, SimpleQueue
|
||||||
|
from weakref import WeakSet, ReferenceType, ref
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
@ -73,6 +74,7 @@ class BaseTest(unittest.TestCase):
|
||||||
Array, LibraryLoader,
|
Array, LibraryLoader,
|
||||||
SplitResult, ParseResult,
|
SplitResult, ParseResult,
|
||||||
ValueProxy, ApplyResult,
|
ValueProxy, ApplyResult,
|
||||||
|
WeakSet, ReferenceType, ref,
|
||||||
ShareableList, SimpleQueue,
|
ShareableList, SimpleQueue,
|
||||||
Future, _WorkItem,
|
Future, _WorkItem,
|
||||||
Morsel,
|
Morsel,
|
||||||
|
|
|
@ -362,6 +362,12 @@ static PyMemberDef weakref_members[] = {
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PyMethodDef weakref_methods[] = {
|
||||||
|
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
|
||||||
|
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
|
||||||
|
{NULL} /* Sentinel */
|
||||||
|
};
|
||||||
|
|
||||||
PyTypeObject
|
PyTypeObject
|
||||||
_PyWeakref_RefType = {
|
_PyWeakref_RefType = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
|
@ -392,7 +398,7 @@ _PyWeakref_RefType = {
|
||||||
0, /*tp_weaklistoffset*/
|
0, /*tp_weaklistoffset*/
|
||||||
0, /*tp_iter*/
|
0, /*tp_iter*/
|
||||||
0, /*tp_iternext*/
|
0, /*tp_iternext*/
|
||||||
0, /*tp_methods*/
|
weakref_methods, /*tp_methods*/
|
||||||
weakref_members, /*tp_members*/
|
weakref_members, /*tp_members*/
|
||||||
0, /*tp_getset*/
|
0, /*tp_getset*/
|
||||||
0, /*tp_base*/
|
0, /*tp_base*/
|
||||||
|
|
Loading…
Reference in New Issue