Skip to content

Commit 988f1ec

Browse files
authored
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.
1 parent cfb41e8 commit 988f1ec

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

Modules/_contextvarsmodule.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,15 @@ static PyMethodDef _contextvars_methods[] = {
3030
static int
3131
_contextvars_exec(PyObject *m)
3232
{
33-
Py_INCREF(&PyContext_Type);
34-
if (PyModule_AddObject(m, "Context",
35-
(PyObject *)&PyContext_Type) < 0)
36-
{
37-
Py_DECREF(&PyContext_Type);
33+
if (PyModule_AddType(m, &PyContext_Type) < 0) {
3834
return -1;
3935
}
40-
41-
Py_INCREF(&PyContextVar_Type);
42-
if (PyModule_AddObject(m, "ContextVar",
43-
(PyObject *)&PyContextVar_Type) < 0)
44-
{
45-
Py_DECREF(&PyContextVar_Type);
36+
if (PyModule_AddType(m, &PyContextVar_Type) < 0) {
4637
return -1;
4738
}
48-
49-
Py_INCREF(&PyContextToken_Type);
50-
if (PyModule_AddObject(m, "Token",
51-
(PyObject *)&PyContextToken_Type) < 0)
52-
{
53-
Py_DECREF(&PyContextToken_Type);
39+
if (PyModule_AddType(m, &PyContextToken_Type) < 0) {
5440
return -1;
5541
}
56-
5742
return 0;
5843
}
5944

Python/context.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ static PyMappingMethods PyContext_as_mapping = {
703703

704704
PyTypeObject PyContext_Type = {
705705
PyVarObject_HEAD_INIT(&PyType_Type, 0)
706-
"Context",
706+
"_contextvars.Context",
707707
sizeof(PyContext),
708708
.tp_methods = PyContext_methods,
709709
.tp_as_mapping = &PyContext_as_mapping,
@@ -1056,7 +1056,7 @@ static PyMethodDef PyContextVar_methods[] = {
10561056

10571057
PyTypeObject PyContextVar_Type = {
10581058
PyVarObject_HEAD_INIT(&PyType_Type, 0)
1059-
"ContextVar",
1059+
"_contextvars.ContextVar",
10601060
sizeof(PyContextVar),
10611061
.tp_methods = PyContextVar_methods,
10621062
.tp_members = PyContextVar_members,
@@ -1197,7 +1197,7 @@ static PyMethodDef PyContextTokenType_methods[] = {
11971197

11981198
PyTypeObject PyContextToken_Type = {
11991199
PyVarObject_HEAD_INIT(&PyType_Type, 0)
1200-
"Token",
1200+
"_contextvars.Token",
12011201
sizeof(PyContextToken),
12021202
.tp_methods = PyContextTokenType_methods,
12031203
.tp_getset = PyContextTokenType_getsetlist,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy