aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/Modules/_typingmodule.c
diff options
context:
space:
mode:
authorthegeorg <thegeorg@yandex-team.com>2024-02-19 02:38:52 +0300
committerthegeorg <thegeorg@yandex-team.com>2024-02-19 02:50:43 +0300
commitd96fa07134c06472bfee6718b5cfd1679196fc99 (patch)
tree31ec344fa9d3ff8dc038692516b6438dfbdb8a2d /contrib/tools/python3/Modules/_typingmodule.c
parent452cf9e068aef7110e35e654c5d47eb80111ef89 (diff)
downloadydb-d96fa07134c06472bfee6718b5cfd1679196fc99.tar.gz
Sync contrib/tools/python3 layout with upstream
* Move src/ subdir contents to the top of the layout * Rename self-written lib -> lib2 to avoid CaseFolding warning from the VCS * Regenerate contrib/libs/python proxy-headers accordingly 4ccc62ac1511abcf0fed14ccade38e984e088f1e
Diffstat (limited to 'contrib/tools/python3/Modules/_typingmodule.c')
-rw-r--r--contrib/tools/python3/Modules/_typingmodule.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/contrib/tools/python3/Modules/_typingmodule.c b/contrib/tools/python3/Modules/_typingmodule.c
new file mode 100644
index 0000000000..39a124a26a
--- /dev/null
+++ b/contrib/tools/python3/Modules/_typingmodule.c
@@ -0,0 +1,90 @@
+/* typing accelerator C extension: _typing module. */
+
+#ifndef Py_BUILD_CORE
+#define Py_BUILD_CORE
+#endif
+
+#include "Python.h"
+#include "internal/pycore_interp.h"
+#include "internal/pycore_typevarobject.h"
+#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]*/
+{
+ return Py_NewRef(x);
+}
+
+
+static PyMethodDef typing_methods[] = {
+ _TYPING__IDFUNC_METHODDEF
+ {NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(typing_doc,
+"Accelerators for the typing module.\n");
+
+static int
+_typing_exec(PyObject *m)
+{
+ PyInterpreterState *interp = PyInterpreterState_Get();
+
+#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
+ if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+static struct PyModuleDef_Slot _typingmodule_slots[] = {
+ {Py_mod_exec, _typing_exec},
+ {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
+ {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);
+}