bpo-1635741: _contextvars uses PyModule_AddType() (GH-23147)

Replace PyModule_AddObject() with PyModule_AddType() in the
_contextvars module (Python-ast.c).

Add also the module name to _contextvars types name.
This commit is contained in:
Victor Stinner 2020-11-04 16:33:55 +01:00 committed by GitHub
parent cfb41e80c1
commit 988f1ec8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 21 deletions

View File

@ -30,30 +30,15 @@ static PyMethodDef _contextvars_methods[] = {
static int static int
_contextvars_exec(PyObject *m) _contextvars_exec(PyObject *m)
{ {
Py_INCREF(&PyContext_Type); if (PyModule_AddType(m, &PyContext_Type) < 0) {
if (PyModule_AddObject(m, "Context",
(PyObject *)&PyContext_Type) < 0)
{
Py_DECREF(&PyContext_Type);
return -1; return -1;
} }
if (PyModule_AddType(m, &PyContextVar_Type) < 0) {
Py_INCREF(&PyContextVar_Type);
if (PyModule_AddObject(m, "ContextVar",
(PyObject *)&PyContextVar_Type) < 0)
{
Py_DECREF(&PyContextVar_Type);
return -1; return -1;
} }
if (PyModule_AddType(m, &PyContextToken_Type) < 0) {
Py_INCREF(&PyContextToken_Type);
if (PyModule_AddObject(m, "Token",
(PyObject *)&PyContextToken_Type) < 0)
{
Py_DECREF(&PyContextToken_Type);
return -1; return -1;
} }
return 0; return 0;
} }

View File

@ -703,7 +703,7 @@ static PyMappingMethods PyContext_as_mapping = {
PyTypeObject PyContext_Type = { PyTypeObject PyContext_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
"Context", "_contextvars.Context",
sizeof(PyContext), sizeof(PyContext),
.tp_methods = PyContext_methods, .tp_methods = PyContext_methods,
.tp_as_mapping = &PyContext_as_mapping, .tp_as_mapping = &PyContext_as_mapping,
@ -1056,7 +1056,7 @@ static PyMethodDef PyContextVar_methods[] = {
PyTypeObject PyContextVar_Type = { PyTypeObject PyContextVar_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
"ContextVar", "_contextvars.ContextVar",
sizeof(PyContextVar), sizeof(PyContextVar),
.tp_methods = PyContextVar_methods, .tp_methods = PyContextVar_methods,
.tp_members = PyContextVar_members, .tp_members = PyContextVar_members,
@ -1197,7 +1197,7 @@ static PyMethodDef PyContextTokenType_methods[] = {
PyTypeObject PyContextToken_Type = { PyTypeObject PyContextToken_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
"Token", "_contextvars.Token",
sizeof(PyContextToken), sizeof(PyContextToken),
.tp_methods = PyContextTokenType_methods, .tp_methods = PyContextTokenType_methods,
.tp_getset = PyContextTokenType_getsetlist, .tp_getset = PyContextTokenType_getsetlist,