]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-142873: Do not check for `PyContextVar_CheckExact` twice in `PyContextVar_S...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 17 Dec 2025 17:04:39 +0000 (18:04 +0100)
committerGitHub <noreply@github.com>
Wed, 17 Dec 2025 17:04:39 +0000 (17:04 +0000)
gh-142873: Do not check for `PyContextVar_CheckExact` twice in `PyContextVar_Set` (GH-142874)
(cherry picked from commit e61a447d0e0753621e8fc347e99dfc87884d68ab)

Co-authored-by: sobolevn <mail@sobolevn.me>
Python/context.c

index c9675f44772cb46e50f8a88483ee8715b2b65441..1b2797b8af5bd60a023e7d5a647319d68c5e971f 100644 (file)
@@ -264,12 +264,6 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
     ENSURE_ContextVar(ovar, NULL)
     PyContextVar *var = (PyContextVar *)ovar;
 
-    if (!PyContextVar_CheckExact(var)) {
-        PyErr_SetString(
-            PyExc_TypeError, "an instance of ContextVar was expected");
-        return NULL;
-    }
-
     PyContext *ctx = context_get();
     if (ctx == NULL) {
         return NULL;
@@ -979,12 +973,6 @@ static PyObject *
 _contextvars_ContextVar_get_impl(PyContextVar *self, PyObject *default_value)
 /*[clinic end generated code: output=0746bd0aa2ced7bf input=30aa2ab9e433e401]*/
 {
-    if (!PyContextVar_CheckExact(self)) {
-        PyErr_SetString(
-            PyExc_TypeError, "an instance of ContextVar was expected");
-        return NULL;
-    }
-
     PyObject *val;
     if (PyContextVar_Get((PyObject *)self, default_value, &val) < 0) {
         return NULL;