Skip to content
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
7 changes: 4 additions & 3 deletions Lib/test/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ def test_context_var_new_1(self):

self.assertNotEqual(hash(c), hash('aaa'))

def test_context_var_new_2(self):
self.assertIsNone(contextvars.ContextVar[int])

@isolated_context
def test_context_var_repr_1(self):
c = contextvars.ContextVar('a')
Expand Down Expand Up @@ -361,6 +358,10 @@ def sub(num):
tp.shutdown()
self.assertEqual(results, list(range(10)))

def test_contextvar_getitem(self):
clss = contextvars.ContextVar
self.assertEqual(clss[str], clss)


# HAMT Tests

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return class from ``ContextVar.__class_getitem__`` to simplify subclassing.
7 changes: 4 additions & 3 deletions Python/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,10 @@ _contextvars_ContextVar_reset(PyContextVar *self, PyObject *token)


static PyObject *
contextvar_cls_getitem(PyObject *self, PyObject *args)
contextvar_cls_getitem(PyObject *self, PyObject *arg)
{
Py_RETURN_NONE;
Py_INCREF(self);
return self;
}

static PyMemberDef PyContextVar_members[] = {
Expand All @@ -1025,7 +1026,7 @@ static PyMethodDef PyContextVar_methods[] = {
_CONTEXTVARS_CONTEXTVAR_SET_METHODDEF
_CONTEXTVARS_CONTEXTVAR_RESET_METHODDEF
{"__class_getitem__", contextvar_cls_getitem,
METH_VARARGS | METH_STATIC, NULL},
METH_O | METH_CLASS, NULL},
{NULL, NULL}
};

Expand Down