Generated by Cython 3.0.11

Yellow lines hint at Python interaction.
Click on a line that starts with a "`+`" to see the C code that Cython generated for it.

Raw output: singleton.c

    +01: # cython: language_level=3, embedsignature=True, boundscheck=False, wraparound=True, initializedcheck=False

      __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

     02: # Copyright (C) 2018-present Jesus Lara

     03: #

     04: cdef class Singleton(type):

     05:     """Singleton.

     06:     Metaclass for Singleton instances.

     07:     Returns:

     08:         cls: a singleton version of the class, there are only one

     09:         version of the instance any time.

     10:     """

    +11:     def __init__(cls, name, bases, attrs, **kwargs):

    /* Python wrapper */
    static int __pyx_pw_9datamodel_8typedefs_9singleton_9Singleton_1__init__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static int __pyx_pw_9datamodel_8typedefs_9singleton_9Singleton_1__init__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_name = 0;
      PyObject *__pyx_v_bases = 0;
      PyObject *__pyx_v_attrs = 0;
      CYTHON_UNUSED PyObject *__pyx_v_kwargs = 0;
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      int __pyx_r;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_MACROS
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return -1;
      __Pyx_GOTREF(__pyx_v_kwargs);
      {
        PyObject **__pyx_pyargnames[] = {&__pyx_n_s_name,&__pyx_n_s_bases,&__pyx_n_s_attrs,0};
      PyObject* values[3] = {0,0,0};
        if (__pyx_kwds) {
          Py_ssize_t kw_args;
          switch (__pyx_nargs) {
            case  3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
            CYTHON_FALLTHROUGH;
            case  2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
            CYTHON_FALLTHROUGH;
            case  1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
            CYTHON_FALLTHROUGH;
            case  0: break;
            default: goto __pyx_L5_argtuple_error;
          }
          kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds);
          switch (__pyx_nargs) {
            case  0:
            if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_name)) != 0)) {
              (void)__Pyx_Arg_NewRef_VARARGS(values[0]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
            else goto __pyx_L5_argtuple_error;
            CYTHON_FALLTHROUGH;
            case  1:
            if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_bases)) != 0)) {
              (void)__Pyx_Arg_NewRef_VARARGS(values[1]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); __PYX_ERR(0, 11, __pyx_L3_error)
            }
            CYTHON_FALLTHROUGH;
            case  2:
            if (likely((values[2] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_attrs)) != 0)) {
              (void)__Pyx_Arg_NewRef_VARARGS(values[2]);
              kw_args--;
            }
            else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error)
            else {
              __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); __PYX_ERR(0, 11, __pyx_L3_error)
            }
          }
          if (unlikely(kw_args > 0)) {
            const Py_ssize_t kwd_pos_args = __pyx_nargs;
            if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 11, __pyx_L3_error)
          }
        } else if (unlikely(__pyx_nargs != 3)) {
          goto __pyx_L5_argtuple_error;
        } else {
          values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0);
          values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1);
          values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2);
        }
        __pyx_v_name = values[0];
        __pyx_v_bases = values[1];
        __pyx_v_attrs = values[2];
      }
      goto __pyx_L6_skip;
      __pyx_L5_argtuple_error:;
      __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 11, __pyx_L3_error)
      __pyx_L6_skip:;
      goto __pyx_L4_argument_unpacking_done;
      __pyx_L3_error:;
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
        }
      }
      __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0;
      __Pyx_AddTraceback("datamodel.typedefs.singleton.Singleton.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __Pyx_RefNannyFinishContext();
      return -1;
      __pyx_L4_argument_unpacking_done:;
      __pyx_r = __pyx_pf_9datamodel_8typedefs_9singleton_9Singleton___init__(((struct __pyx_obj_9datamodel_8typedefs_9singleton_Singleton *)__pyx_v_cls), __pyx_v_name, __pyx_v_bases, __pyx_v_attrs, __pyx_v_kwargs);
      int __pyx_lineno = 0;
      const char *__pyx_filename = NULL;
      int __pyx_clineno = 0;

      /* function exit code */
      __Pyx_DECREF(__pyx_v_kwargs);
      {
        Py_ssize_t __pyx_temp;
        for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) {
          __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]);
        }
      }
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static int __pyx_pf_9datamodel_8typedefs_9singleton_9Singleton___init__(struct __pyx_obj_9datamodel_8typedefs_9singleton_Singleton *__pyx_v_cls, PyObject *__pyx_v_name, PyObject *__pyx_v_bases, PyObject *__pyx_v_attrs, CYTHON_UNUSED PyObject *__pyx_v_kwargs) {
      int __pyx_r;
    /* … */
      /* function exit code */
      __pyx_r = 0;
      goto __pyx_L0;
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_1);
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_AddTraceback("datamodel.typedefs.singleton.Singleton.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = -1;
      __pyx_L0:;
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +12:         super().__init__(name, bases, attrs)

      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_INCREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
      __Pyx_GIVEREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton))) __PYX_ERR(0, 12, __pyx_L1_error);
      __Pyx_INCREF((PyObject *)__pyx_v_cls);
      __Pyx_GIVEREF((PyObject *)__pyx_v_cls);
      if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_cls))) __PYX_ERR(0, 12, __pyx_L1_error);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 12, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_init); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 12, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      #if CYTHON_UNPACK_METHODS
      if (likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #endif
      {
        PyObject *__pyx_callargs[4] = {__pyx_t_3, __pyx_v_name, __pyx_v_bases, __pyx_v_attrs};
        __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 3+__pyx_t_4);
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    +13:         cls._instances = {}

      __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_v_cls->_instances);
      __Pyx_DECREF(__pyx_v_cls->_instances);
      __pyx_v_cls->_instances = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

    +14:         cls.__initialized__ = False

      __pyx_v_cls->__pyx___initialized__ = 0;

     15:

    +16:     def __call__(cls, *args, **kwargs):

    /* Python wrapper */
    static PyObject *__pyx_pw_9datamodel_8typedefs_9singleton_9Singleton_3__call__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
    static PyObject *__pyx_pw_9datamodel_8typedefs_9singleton_9Singleton_3__call__(PyObject *__pyx_v_cls, PyObject *__pyx_args, PyObject *__pyx_kwds) {
      PyObject *__pyx_v_args = 0;
      PyObject *__pyx_v_kwargs = 0;
      CYTHON_UNUSED Py_ssize_t __pyx_nargs;
      CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
      PyObject *__pyx_r = 0;
      __Pyx_RefNannyDeclarations
      __Pyx_RefNannySetupContext("__call__ (wrapper)", 0);
      #if CYTHON_ASSUME_SAFE_MACROS
      __pyx_nargs = PyTuple_GET_SIZE(__pyx_args);
      #else
      __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL;
      #endif
      __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs);
      if (unlikely(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__call__", 1))) return NULL;
      if (unlikely(__pyx_kwds)) {
        __pyx_v_kwargs = __Pyx_KwargsAsDict_VARARGS(__pyx_kwds, __pyx_kwvalues);
        if (unlikely(!__pyx_v_kwargs)) return NULL;
        __Pyx_GOTREF(__pyx_v_kwargs);
      } else {
        __pyx_v_kwargs = PyDict_New();
        if (unlikely(!__pyx_v_kwargs)) return NULL;
        __Pyx_GOTREF(__pyx_v_kwargs);
      }
      __Pyx_INCREF(__pyx_args);
      __pyx_v_args = __pyx_args;
      __pyx_r = __pyx_pf_9datamodel_8typedefs_9singleton_9Singleton_2__call__(((struct __pyx_obj_9datamodel_8typedefs_9singleton_Singleton *)__pyx_v_cls), __pyx_v_args, __pyx_v_kwargs);

      /* function exit code */
      __Pyx_DECREF(__pyx_v_args);
      __Pyx_DECREF(__pyx_v_kwargs);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    static PyObject *__pyx_pf_9datamodel_8typedefs_9singleton_9Singleton_2__call__(struct __pyx_obj_9datamodel_8typedefs_9singleton_Singleton *__pyx_v_cls, PyObject *__pyx_v_args, PyObject *__pyx_v_kwargs) {
      CYTHON_UNUSED PyObject *__pyx_v_instance = NULL;
      PyObject *__pyx_r = NULL;
    /* … */
      /* function exit code */
      __pyx_L1_error:;
      __Pyx_XDECREF(__pyx_t_2);
      __Pyx_XDECREF(__pyx_t_3);
      __Pyx_XDECREF(__pyx_t_4);
      __Pyx_AddTraceback("datamodel.typedefs.singleton.Singleton.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename);
      __pyx_r = NULL;
      __pyx_L0:;
      __Pyx_XDECREF(__pyx_v_instance);
      __Pyx_XGIVEREF(__pyx_r);
      __Pyx_RefNannyFinishContext();
      return __pyx_r;
    }

    +17:         if cls not in cls._instances:

      if (unlikely(__pyx_v_cls->_instances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 17, __pyx_L1_error)
      }
      __pyx_t_1 = (__Pyx_PyDict_ContainsTF(((PyObject *)__pyx_v_cls), __pyx_v_cls->_instances, Py_NE)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 17, __pyx_L1_error)
      if (__pyx_t_1) {
    /* … */
        goto __pyx_L3;
      }

     18:             # First time creating an instance for this class

    +19:             cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)

        __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_INCREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
        __Pyx_GIVEREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton))) __PYX_ERR(0, 19, __pyx_L1_error);
        __Pyx_INCREF((PyObject *)__pyx_v_cls);
        __Pyx_GIVEREF((PyObject *)__pyx_v_cls);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_cls))) __PYX_ERR(0, 19, __pyx_L1_error);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_call); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_v_args, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (unlikely(__pyx_v_cls->_instances == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 19, __pyx_L1_error)
        }
        if (unlikely((PyDict_SetItem(__pyx_v_cls->_instances, ((PyObject *)__pyx_v_cls), __pyx_t_4) < 0))) __PYX_ERR(0, 19, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    +20:             cls.__initialized__ = True

        __pyx_v_cls->__pyx___initialized__ = 1;

    +21:         elif not cls.__initialized__:

      __pyx_t_1 = (!__pyx_v_cls->__pyx___initialized__);
      if (__pyx_t_1) {
    /* … */
      }
      __pyx_L3:;

    +22:             instance = super(Singleton, cls).__call__(*args, **kwargs)

        __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 22, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_INCREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
        __Pyx_GIVEREF((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, ((PyObject *)__pyx_ptype_9datamodel_8typedefs_9singleton_Singleton))) __PYX_ERR(0, 22, __pyx_L1_error);
        __Pyx_INCREF((PyObject *)__pyx_v_cls);
        __Pyx_GIVEREF((PyObject *)__pyx_v_cls);
        if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, ((PyObject *)__pyx_v_cls))) __PYX_ERR(0, 22, __pyx_L1_error);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_call); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 22, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = PyDict_Copy(__pyx_v_kwargs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 22, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_v_args, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 22, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_v_instance = __pyx_t_2;
        __pyx_t_2 = 0;

    +23:             cls.__initialized__ = True

        __pyx_v_cls->__pyx___initialized__ = 1;

    +24:         return cls._instances[cls]

      __Pyx_XDECREF(__pyx_r);
      if (unlikely(__pyx_v_cls->_instances == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 24, __pyx_L1_error)
      }
      __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_cls->_instances, ((PyObject *)__pyx_v_cls)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L0;