(root)/
Python-3.12.0/
Modules/
_typingmodule.c
       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 "clinic/_typingmodule.c.h"
      11  
      12  /*[clinic input]
      13  module _typing
      14  
      15  [clinic start generated code]*/
      16  /*[clinic end generated code: output=da39a3ee5e6b4b0d input=1db35baf1c72942b]*/
      17  
      18  /* helper function to make typing.NewType.__call__ method faster */
      19  
      20  /*[clinic input]
      21  _typing._idfunc -> object
      22  
      23      x: object
      24      /
      25  
      26  [clinic start generated code]*/
      27  
      28  static PyObject *
      29  _typing__idfunc(PyObject *module, PyObject *x)
      30  /*[clinic end generated code: output=63c38be4a6ec5f2c input=49f17284b43de451]*/
      31  {
      32      return Py_NewRef(x);
      33  }
      34  
      35  
      36  static PyMethodDef typing_methods[] = {
      37      _TYPING__IDFUNC_METHODDEF
      38      {NULL, NULL, 0, NULL}
      39  };
      40  
      41  PyDoc_STRVAR(typing_doc,
      42  "Accelerators for the typing module.\n");
      43  
      44  static int
      45  _typing_exec(PyObject *m)
      46  {
      47      PyInterpreterState *interp = PyInterpreterState_Get();
      48  
      49  #define EXPORT_TYPE(name, typename) \
      50      if (PyModule_AddObjectRef(m, name, \
      51                                (PyObject *)interp->cached_objects.typename) < 0) { \
      52          return -1; \
      53      }
      54  
      55      EXPORT_TYPE("TypeVar", typevar_type);
      56      EXPORT_TYPE("TypeVarTuple", typevartuple_type);
      57      EXPORT_TYPE("ParamSpec", paramspec_type);
      58      EXPORT_TYPE("ParamSpecArgs", paramspecargs_type);
      59      EXPORT_TYPE("ParamSpecKwargs", paramspeckwargs_type);
      60      EXPORT_TYPE("Generic", generic_type);
      61  #undef EXPORT_TYPE
      62      if (PyModule_AddObjectRef(m, "TypeAliasType", (PyObject *)&_PyTypeAlias_Type) < 0) {
      63          return -1;
      64      }
      65      return 0;
      66  }
      67  
      68  static struct PyModuleDef_Slot _typingmodule_slots[] = {
      69      {Py_mod_exec, _typing_exec},
      70      {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
      71      {0, NULL}
      72  };
      73  
      74  static struct PyModuleDef typingmodule = {
      75          PyModuleDef_HEAD_INIT,
      76          "_typing",
      77          typing_doc,
      78          0,
      79          typing_methods,
      80          _typingmodule_slots,
      81          NULL,
      82          NULL,
      83          NULL
      84  };
      85  
      86  PyMODINIT_FUNC
      87  PyInit__typing(void)
      88  {
      89      return PyModuleDef_Init(&typingmodule);
      90  }