2021-07-22 18:06:54 -03:00
|
|
|
/* typing accelerator C extension: _typing module. */
|
|
|
|
|
2023-05-16 00:36:23 -03:00
|
|
|
#ifndef Py_BUILD_CORE
|
|
|
|
#define Py_BUILD_CORE
|
|
|
|
#endif
|
|
|
|
|
2021-07-22 18:06:54 -03:00
|
|
|
#include "Python.h"
|
2023-07-02 13:37:37 -03:00
|
|
|
#include "pycore_interp.h"
|
|
|
|
#include "pycore_pystate.h" // _PyInterpreterState_GET()
|
|
|
|
#include "pycore_typevarobject.h"
|
2021-07-22 18:06:54 -03:00
|
|
|
#include "clinic/_typingmodule.c.h"
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
module _typing
|
|
|
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=1db35baf1c72942b]*/
|
|
|
|
|
|
|
|
/* helper function to make typing.NewType.__call__ method faster */
|
|
|
|
|
|
|
|
/*[clinic input]
|
|
|
|
_typing._idfunc -> object
|
|
|
|
|
|
|
|
x: object
|
|
|
|
/
|
|
|
|
|
|
|
|
[clinic start generated code]*/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
_typing__idfunc(PyObject *module, PyObject *x)
|
|
|
|
/*[clinic end generated code: output=63c38be4a6ec5f2c input=49f17284b43de451]*/
|
|
|
|
{
|
2022-11-14 08:44:56 -04:00
|
|
|
return Py_NewRef(x);
|
2021-07-22 18:06:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static PyMethodDef typing_methods[] = {
|
|
|
|
_TYPING__IDFUNC_METHODDEF
|
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
PyDoc_STRVAR(typing_doc,
|
2023-08-13 06:24:59 -03:00
|
|
|
"Primitives and accelerators for the typing module.\n");
|
2021-07-22 18:06:54 -03:00
|
|
|
|
2023-05-16 00:36:23 -03:00
|
|
|
static int
|
|
|
|
_typing_exec(PyObject *m)
|
|
|
|
{
|
2023-07-02 13:37:37 -03:00
|
|
|
PyInterpreterState *interp = _PyInterpreterState_GET();
|
2023-05-16 00:36:23 -03:00
|
|
|
|
|
|
|
#define EXPORT_TYPE(name, typename) \
|
|
|
|
if (PyModule_AddObjectRef(m, name, \
|
|
|
|
(PyObject *)interp->cached_objects.typename) < 0) { \
|
|
|
|
return -1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_TYPE("TypeVar", typevar_type);
|
|
|
|
EXPORT_TYPE("TypeVarTuple", typevartuple_type);
|
|
|
|
EXPORT_TYPE("ParamSpec", paramspec_type);
|
|
|
|
EXPORT_TYPE("ParamSpecArgs", paramspecargs_type);
|
|
|
|
EXPORT_TYPE("ParamSpecKwargs", paramspeckwargs_type);
|
|
|
|
EXPORT_TYPE("Generic", generic_type);
|
|
|
|
#undef EXPORT_TYPE
|
2023-05-18 19:56:15 -03:00
|
|
|
if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2024-05-03 10:17:32 -03:00
|
|
|
if (PyModule_AddObjectRef(m, "NoDefault", (PyObject *)&_Py_NoDefaultStruct) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2023-05-16 00:36:23 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-22 18:06:54 -03:00
|
|
|
static struct PyModuleDef_Slot _typingmodule_slots[] = {
|
2023-05-16 00:36:23 -03:00
|
|
|
{Py_mod_exec, _typing_exec},
|
2023-05-05 18:11:27 -03:00
|
|
|
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
|
2024-05-03 12:30:55 -03:00
|
|
|
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
|
2021-07-22 18:06:54 -03:00
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct PyModuleDef typingmodule = {
|
|
|
|
PyModuleDef_HEAD_INIT,
|
|
|
|
"_typing",
|
|
|
|
typing_doc,
|
|
|
|
0,
|
|
|
|
typing_methods,
|
|
|
|
_typingmodule_slots,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
PyMODINIT_FUNC
|
|
|
|
PyInit__typing(void)
|
|
|
|
{
|
|
|
|
return PyModuleDef_Init(&typingmodule);
|
|
|
|
}
|