]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-1635741: _contextvars uses PyModule_AddType() (GH-23147)
authorVictor Stinner <vstinner@python.org>
Wed, 4 Nov 2020 15:33:55 +0000 (16:33 +0100)
committerGitHub <noreply@github.com>
Wed, 4 Nov 2020 15:33:55 +0000 (16:33 +0100)
Replace PyModule_AddObject() with PyModule_AddType() in the
_contextvars module (Python-ast.c).

Add also the module name to _contextvars types name.

Modules/_contextvarsmodule.c
Python/context.c

index d6d7f375d1230782b36c2f344ac8c704ff56a94f..d13b5962c13c445475775958e87671836132e394 100644 (file)
@@ -30,30 +30,15 @@ static PyMethodDef _contextvars_methods[] = {
 static int
 _contextvars_exec(PyObject *m)
 {
-    Py_INCREF(&PyContext_Type);
-    if (PyModule_AddObject(m, "Context",
-                           (PyObject *)&PyContext_Type) < 0)
-    {
-        Py_DECREF(&PyContext_Type);
+    if (PyModule_AddType(m, &PyContext_Type) < 0) {
         return -1;
     }
-
-    Py_INCREF(&PyContextVar_Type);
-    if (PyModule_AddObject(m, "ContextVar",
-                           (PyObject *)&PyContextVar_Type) < 0)
-    {
-        Py_DECREF(&PyContextVar_Type);
+    if (PyModule_AddType(m, &PyContextVar_Type) < 0) {
         return -1;
     }
-
-    Py_INCREF(&PyContextToken_Type);
-    if (PyModule_AddObject(m, "Token",
-                           (PyObject *)&PyContextToken_Type) < 0)
-    {
-        Py_DECREF(&PyContextToken_Type);
+    if (PyModule_AddType(m, &PyContextToken_Type) < 0) {
         return -1;
     }
-
     return 0;
 }
 
index 15d8b8ea4b9b61046761e73746581e807c621e0f..82826bf928fa05107dfbb35e119c2eccda439b2a 100644 (file)
@@ -703,7 +703,7 @@ static PyMappingMethods PyContext_as_mapping = {
 
 PyTypeObject PyContext_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "Context",
+    "_contextvars.Context",
     sizeof(PyContext),
     .tp_methods = PyContext_methods,
     .tp_as_mapping = &PyContext_as_mapping,
@@ -1056,7 +1056,7 @@ static PyMethodDef PyContextVar_methods[] = {
 
 PyTypeObject PyContextVar_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "ContextVar",
+    "_contextvars.ContextVar",
     sizeof(PyContextVar),
     .tp_methods = PyContextVar_methods,
     .tp_members = PyContextVar_members,
@@ -1197,7 +1197,7 @@ static PyMethodDef PyContextTokenType_methods[] = {
 
 PyTypeObject PyContextToken_Type = {
     PyVarObject_HEAD_INIT(&PyType_Type, 0)
-    "Token",
+    "_contextvars.Token",
     sizeof(PyContextToken),
     .tp_methods = PyContextTokenType_methods,
     .tp_getset = PyContextTokenType_getsetlist,