Skip to content

Commit 7915b38

Browse files
committed
Make ContextVar generic
1 parent 305d399 commit 7915b38

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

Lib/test/test_genericalias.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from concurrent.futures import Future
1010
from concurrent.futures.thread import _WorkItem
1111
from contextlib import AbstractContextManager, AbstractAsyncContextManager
12-
from contextvars import Token
12+
from contextvars import ContextVar, Token
1313
from dataclasses import Field
1414
from mailbox import Mailbox, _PartialFile
1515
from ctypes import Array, LibraryLoader
@@ -57,7 +57,7 @@ def test_subscriptable(self):
5757
Container, Collection,
5858
Callable,
5959
Mailbox, _PartialFile,
60-
Token,
60+
ContextVar, Token,
6161
Field,
6262
Set, MutableSet,
6363
Mapping, MutableMapping, MappingView,

Python/context.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,13 +1023,6 @@ _contextvars_ContextVar_reset(PyContextVar *self, PyObject *token)
10231023
}
10241024

10251025

1026-
static PyObject *
1027-
contextvar_cls_getitem(PyObject *self, PyObject *arg)
1028-
{
1029-
Py_INCREF(self);
1030-
return self;
1031-
}
1032-
10331026
static PyMemberDef PyContextVar_members[] = {
10341027
{"name", T_OBJECT, offsetof(PyContextVar, var_name), READONLY},
10351028
{NULL}
@@ -1039,8 +1032,8 @@ static PyMethodDef PyContextVar_methods[] = {
10391032
_CONTEXTVARS_CONTEXTVAR_GET_METHODDEF
10401033
_CONTEXTVARS_CONTEXTVAR_SET_METHODDEF
10411034
_CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF
1042-
{"__class_getitem__", contextvar_cls_getitem,
1043-
METH_O | METH_CLASS, NULL},
1035+
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
1036+
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
10441037
{NULL, NULL}
10451038
};
10461039

0 commit comments

Comments
 (0)