/src/cpython/Modules/_typingmodule.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* typing accelerator C extension: _typing module. */ |
2 | | |
3 | | #ifndef Py_BUILD_CORE |
4 | | #define Py_BUILD_CORE |
5 | | #endif |
6 | | |
7 | | #include "Python.h" |
8 | | #include "internal/pycore_interp.h" |
9 | | #include "internal/pycore_typevarobject.h" |
10 | | #include "internal/pycore_unionobject.h" // _PyUnion_Type |
11 | | #include "pycore_pystate.h" // _PyInterpreterState_GET() |
12 | | #include "clinic/_typingmodule.c.h" |
13 | | |
14 | | /*[clinic input] |
15 | | module _typing |
16 | | |
17 | | [clinic start generated code]*/ |
18 | | /*[clinic end generated code: output=da39a3ee5e6b4b0d input=1db35baf1c72942b]*/ |
19 | | |
20 | | /* helper function to make typing.NewType.__call__ method faster */ |
21 | | |
22 | | /*[clinic input] |
23 | | _typing._idfunc -> object |
24 | | |
25 | | x: object |
26 | | / |
27 | | |
28 | | [clinic start generated code]*/ |
29 | | |
30 | | static PyObject * |
31 | | _typing__idfunc(PyObject *module, PyObject *x) |
32 | | /*[clinic end generated code: output=63c38be4a6ec5f2c input=49f17284b43de451]*/ |
33 | 0 | { |
34 | 0 | return Py_NewRef(x); |
35 | 0 | } |
36 | | |
37 | | |
38 | | static PyMethodDef typing_methods[] = { |
39 | | _TYPING__IDFUNC_METHODDEF |
40 | | {NULL, NULL, 0, NULL} |
41 | | }; |
42 | | |
43 | | PyDoc_STRVAR(typing_doc, |
44 | | "Primitives and accelerators for the typing module.\n"); |
45 | | |
46 | | static int |
47 | | _typing_exec(PyObject *m) |
48 | 0 | { |
49 | 0 | PyInterpreterState *interp = _PyInterpreterState_GET(); |
50 | |
|
51 | 0 | #define EXPORT_TYPE(name, typename) \ |
52 | 0 | if (PyModule_AddObjectRef(m, name, \ |
53 | 0 | (PyObject *)interp->cached_objects.typename) < 0) { \ |
54 | 0 | return -1; \ |
55 | 0 | } |
56 | |
|
57 | 0 | EXPORT_TYPE("TypeVar", typevar_type); |
58 | 0 | EXPORT_TYPE("TypeVarTuple", typevartuple_type); |
59 | 0 | EXPORT_TYPE("ParamSpec", paramspec_type); |
60 | 0 | EXPORT_TYPE("ParamSpecArgs", paramspecargs_type); |
61 | 0 | EXPORT_TYPE("ParamSpecKwargs", paramspeckwargs_type); |
62 | 0 | EXPORT_TYPE("Generic", generic_type); |
63 | 0 | #undef EXPORT_TYPE |
64 | 0 | if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) { |
65 | 0 | return -1; |
66 | 0 | } |
67 | 0 | if (PyModule_AddObjectRef(m, "Union", (PyObject *)&_PyUnion_Type) < 0) { |
68 | 0 | return -1; |
69 | 0 | } |
70 | 0 | if (PyModule_AddObjectRef(m, "NoDefault", (PyObject *)&_Py_NoDefaultStruct) < 0) { |
71 | 0 | return -1; |
72 | 0 | } |
73 | 0 | return 0; |
74 | 0 | } |
75 | | |
76 | | static struct PyModuleDef_Slot _typingmodule_slots[] = { |
77 | | {Py_mod_exec, _typing_exec}, |
78 | | {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED}, |
79 | | {Py_mod_gil, Py_MOD_GIL_NOT_USED}, |
80 | | {0, NULL} |
81 | | }; |
82 | | |
83 | | static struct PyModuleDef typingmodule = { |
84 | | PyModuleDef_HEAD_INIT, |
85 | | "_typing", |
86 | | typing_doc, |
87 | | 0, |
88 | | typing_methods, |
89 | | _typingmodule_slots, |
90 | | NULL, |
91 | | NULL, |
92 | | NULL |
93 | | }; |
94 | | |
95 | | PyMODINIT_FUNC |
96 | | PyInit__typing(void) |
97 | 0 | { |
98 | 0 | return PyModuleDef_Init(&typingmodule); |
99 | 0 | } |