Home | History | Annotate | Download | only in Utility
      1 
      2 
      3 //////////////////// CythonFunction.proto ////////////////////
      4 #define __Pyx_CyFunction_USED 1
      5 #include <structmember.h>
      6 
      7 #define __Pyx_CYFUNCTION_STATICMETHOD  0x01
      8 #define __Pyx_CYFUNCTION_CLASSMETHOD   0x02
      9 #define __Pyx_CYFUNCTION_CCLASS        0x04
     10 
     11 #define __Pyx_CyFunction_GetClosure(f) \
     12     (((__pyx_CyFunctionObject *) (f))->func_closure)
     13 #define __Pyx_CyFunction_GetClassObj(f) \
     14     (((__pyx_CyFunctionObject *) (f))->func_classobj)
     15 
     16 #define __Pyx_CyFunction_Defaults(type, f) \
     17     ((type *)(((__pyx_CyFunctionObject *) (f))->defaults))
     18 #define __Pyx_CyFunction_SetDefaultsGetter(f, g) \
     19     ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g)
     20 
     21 
     22 typedef struct {
     23     PyCFunctionObject func;
     24     PyObject *func_dict;
     25     PyObject *func_weakreflist;
     26     PyObject *func_name;
     27     PyObject *func_qualname;
     28     PyObject *func_doc;
     29     PyObject *func_globals;
     30     PyObject *func_code;
     31     PyObject *func_closure;
     32     PyObject *func_classobj; /* No-args super() class cell */
     33 
     34     /* Dynamic default args and annotations */
     35     void *defaults;
     36     int defaults_pyobjects;
     37     int flags;
     38 
     39     /* Defaults info */
     40     PyObject *defaults_tuple;   /* Const defaults tuple */
     41     PyObject *defaults_kwdict;  /* Const kwonly defaults dict */
     42     PyObject *(*defaults_getter)(PyObject *);
     43     PyObject *func_annotations; /* function annotations dict */
     44 } __pyx_CyFunctionObject;
     45 
     46 static PyTypeObject *__pyx_CyFunctionType = 0;
     47 
     48 #define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code) \
     49     __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
     50 
     51 static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
     52                                       int flags, PyObject* qualname,
     53                                       PyObject *self,
     54                                       PyObject *module, PyObject *globals,
     55                                       PyObject* code);
     56 
     57 static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m,
     58                                                          size_t size,
     59                                                          int pyobjects);
     60 static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m,
     61                                                             PyObject *tuple);
     62 static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
     63                                                              PyObject *dict);
     64 static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
     65                                                               PyObject *dict);
     66 
     67 
     68 static int __Pyx_CyFunction_init(void);
     69 
     70 //////////////////// CythonFunction ////////////////////
     71 //@substitute: naming
     72 //@requires: CommonTypes.c::FetchCommonType
     73 ////@requires: ObjectHandling.c::PyObjectGetAttrStr
     74 
     75 static PyObject *
     76 __Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
     77 {
     78     if (unlikely(op->func_doc == NULL)) {
     79         if (op->func.m_ml->ml_doc) {
     80 #if PY_MAJOR_VERSION >= 3
     81             op->func_doc = PyUnicode_FromString(op->func.m_ml->ml_doc);
     82 #else
     83             op->func_doc = PyString_FromString(op->func.m_ml->ml_doc);
     84 #endif
     85             if (unlikely(op->func_doc == NULL))
     86                 return NULL;
     87         } else {
     88             Py_INCREF(Py_None);
     89             return Py_None;
     90         }
     91     }
     92     Py_INCREF(op->func_doc);
     93     return op->func_doc;
     94 }
     95 
     96 static int
     97 __Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value)
     98 {
     99     PyObject *tmp = op->func_doc;
    100     if (value == NULL)
    101         value = Py_None; /* Mark as deleted */
    102     Py_INCREF(value);
    103     op->func_doc = value;
    104     Py_XDECREF(tmp);
    105     return 0;
    106 }
    107 
    108 static PyObject *
    109 __Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
    110 {
    111     if (unlikely(op->func_name == NULL)) {
    112 #if PY_MAJOR_VERSION >= 3
    113         op->func_name = PyUnicode_InternFromString(op->func.m_ml->ml_name);
    114 #else
    115         op->func_name = PyString_InternFromString(op->func.m_ml->ml_name);
    116 #endif
    117         if (unlikely(op->func_name == NULL))
    118             return NULL;
    119     }
    120     Py_INCREF(op->func_name);
    121     return op->func_name;
    122 }
    123 
    124 static int
    125 __Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value)
    126 {
    127     PyObject *tmp;
    128 
    129 #if PY_MAJOR_VERSION >= 3
    130     if (unlikely(value == NULL || !PyUnicode_Check(value))) {
    131 #else
    132     if (unlikely(value == NULL || !PyString_Check(value))) {
    133 #endif
    134         PyErr_SetString(PyExc_TypeError,
    135                         "__name__ must be set to a string object");
    136         return -1;
    137     }
    138     tmp = op->func_name;
    139     Py_INCREF(value);
    140     op->func_name = value;
    141     Py_XDECREF(tmp);
    142     return 0;
    143 }
    144 
    145 static PyObject *
    146 __Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op)
    147 {
    148     Py_INCREF(op->func_qualname);
    149     return op->func_qualname;
    150 }
    151 
    152 static int
    153 __Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
    154 {
    155     PyObject *tmp;
    156 
    157 #if PY_MAJOR_VERSION >= 3
    158     if (unlikely(value == NULL || !PyUnicode_Check(value))) {
    159 #else
    160     if (unlikely(value == NULL || !PyString_Check(value))) {
    161 #endif
    162         PyErr_SetString(PyExc_TypeError,
    163                         "__qualname__ must be set to a string object");
    164         return -1;
    165     }
    166     tmp = op->func_qualname;
    167     Py_INCREF(value);
    168     op->func_qualname = value;
    169     Py_XDECREF(tmp);
    170     return 0;
    171 }
    172 
    173 static PyObject *
    174 __Pyx_CyFunction_get_self(__pyx_CyFunctionObject *m, CYTHON_UNUSED void *closure)
    175 {
    176     PyObject *self;
    177 
    178     self = m->func_closure;
    179     if (self == NULL)
    180         self = Py_None;
    181     Py_INCREF(self);
    182     return self;
    183 }
    184 
    185 static PyObject *
    186 __Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op)
    187 {
    188     if (unlikely(op->func_dict == NULL)) {
    189         op->func_dict = PyDict_New();
    190         if (unlikely(op->func_dict == NULL))
    191             return NULL;
    192     }
    193     Py_INCREF(op->func_dict);
    194     return op->func_dict;
    195 }
    196 
    197 static int
    198 __Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value)
    199 {
    200     PyObject *tmp;
    201 
    202     if (unlikely(value == NULL)) {
    203         PyErr_SetString(PyExc_TypeError,
    204                "function's dictionary may not be deleted");
    205         return -1;
    206     }
    207     if (unlikely(!PyDict_Check(value))) {
    208         PyErr_SetString(PyExc_TypeError,
    209                "setting function's dictionary to a non-dict");
    210         return -1;
    211     }
    212     tmp = op->func_dict;
    213     Py_INCREF(value);
    214     op->func_dict = value;
    215     Py_XDECREF(tmp);
    216     return 0;
    217 }
    218 
    219 static PyObject *
    220 __Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op)
    221 {
    222     Py_INCREF(op->func_globals);
    223     return op->func_globals;
    224 }
    225 
    226 static PyObject *
    227 __Pyx_CyFunction_get_closure(CYTHON_UNUSED __pyx_CyFunctionObject *op)
    228 {
    229     Py_INCREF(Py_None);
    230     return Py_None;
    231 }
    232 
    233 static PyObject *
    234 __Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op)
    235 {
    236     PyObject* result = (op->func_code) ? op->func_code : Py_None;
    237     Py_INCREF(result);
    238     return result;
    239 }
    240 
    241 static int
    242 __Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    243     PyObject *res = op->defaults_getter((PyObject *) op);
    244     if (unlikely(!res))
    245         return -1;
    246 
    247     /* Cache result */
    248     op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    249     Py_INCREF(op->defaults_tuple);
    250     op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    251     Py_INCREF(op->defaults_kwdict);
    252     Py_DECREF(res);
    253     return 0;
    254 }
    255 
    256 static int
    257 __Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
    258     PyObject* tmp;
    259     if (!value) {
    260         // del => explicit None to prevent rebuilding
    261         value = Py_None;
    262     } else if (value != Py_None && !PyTuple_Check(value)) {
    263         PyErr_SetString(PyExc_TypeError,
    264                         "__defaults__ must be set to a tuple object");
    265         return -1;
    266     }
    267     Py_INCREF(value);
    268     tmp = op->defaults_tuple;
    269     op->defaults_tuple = value;
    270     Py_XDECREF(tmp);
    271     return 0;
    272 }
    273 
    274 static PyObject *
    275 __Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
    276     PyObject* result = op->defaults_tuple;
    277     if (unlikely(!result)) {
    278         if (op->defaults_getter) {
    279             if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
    280             result = op->defaults_tuple;
    281         } else {
    282             result = Py_None;
    283         }
    284     }
    285     Py_INCREF(result);
    286     return result;
    287 }
    288 
    289 static int
    290 __Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
    291     PyObject* tmp;
    292     if (!value) {
    293         // del => explicit None to prevent rebuilding
    294         value = Py_None;
    295     } else if (value != Py_None && !PyDict_Check(value)) {
    296         PyErr_SetString(PyExc_TypeError,
    297                         "__kwdefaults__ must be set to a dict object");
    298         return -1;
    299     }
    300     Py_INCREF(value);
    301     tmp = op->defaults_kwdict;
    302     op->defaults_kwdict = value;
    303     Py_XDECREF(tmp);
    304     return 0;
    305 }
    306 
    307 static PyObject *
    308 __Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
    309     PyObject* result = op->defaults_kwdict;
    310     if (unlikely(!result)) {
    311         if (op->defaults_getter) {
    312             if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
    313             result = op->defaults_kwdict;
    314         } else {
    315             result = Py_None;
    316         }
    317     }
    318     Py_INCREF(result);
    319     return result;
    320 }
    321 
    322 static int
    323 __Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
    324     PyObject* tmp;
    325     if (!value || value == Py_None) {
    326         value = NULL;
    327     } else if (!PyDict_Check(value)) {
    328         PyErr_SetString(PyExc_TypeError,
    329                         "__annotations__ must be set to a dict object");
    330         return -1;
    331     }
    332     Py_XINCREF(value);
    333     tmp = op->func_annotations;
    334     op->func_annotations = value;
    335     Py_XDECREF(tmp);
    336     return 0;
    337 }
    338 
    339 static PyObject *
    340 __Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
    341     PyObject* result = op->func_annotations;
    342     if (unlikely(!result)) {
    343         result = PyDict_New();
    344         if (unlikely(!result)) return NULL;
    345         op->func_annotations = result;
    346     }
    347     Py_INCREF(result);
    348     return result;
    349 }
    350 
    351 //#if PY_VERSION_HEX >= 0x030400C1
    352 //static PyObject *
    353 //__Pyx_CyFunction_get_signature(__pyx_CyFunctionObject *op) {
    354 //    PyObject *inspect_module, *signature_class, *signature;
    355 //    // from inspect import Signature
    356 //    inspect_module = PyImport_ImportModuleLevelObject(PYIDENT("inspect"), NULL, NULL, NULL, 0);
    357 //    if (unlikely(!inspect_module))
    358 //        goto bad;
    359 //    signature_class = __Pyx_PyObject_GetAttrStr(inspect_module, PYIDENT("Signature"));
    360 //    Py_DECREF(inspect_module);
    361 //    if (unlikely(!signature_class))
    362 //        goto bad;
    363 //    // return Signature.from_function(op)
    364 //    signature = PyObject_CallMethodObjArgs(signature_class, PYIDENT("from_function"), op, NULL);
    365 //    Py_DECREF(signature_class);
    366 //    if (likely(signature))
    367 //        return signature;
    368 //bad:
    369 //    // make sure we raise an AttributeError from this property on any errors
    370 //    if (!PyErr_ExceptionMatches(PyExc_AttributeError))
    371 //        PyErr_SetString(PyExc_AttributeError, "failed to calculate __signature__");
    372 //    return NULL;
    373 //}
    374 //#endif
    375 
    376 static PyGetSetDef __pyx_CyFunction_getsets[] = {
    377     {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    378     {(char *) "__doc__",  (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0},
    379     {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    380     {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0},
    381     {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0},
    382     {(char *) "__self__", (getter)__Pyx_CyFunction_get_self, 0, 0, 0},
    383     {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    384     {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0},
    385     {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    386     {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0},
    387     {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    388     {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0},
    389     {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    390     {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0},
    391     {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    392     {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    393     {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    394     {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    395 //#if PY_VERSION_HEX >= 0x030400C1
    396 //    {(char *) "__signature__", (getter)__Pyx_CyFunction_get_signature, 0, 0, 0},
    397 //#endif
    398     {0, 0, 0, 0, 0}
    399 };
    400 
    401 #ifndef PY_WRITE_RESTRICTED /* < Py2.5 */
    402 #define PY_WRITE_RESTRICTED WRITE_RESTRICTED
    403 #endif
    404 
    405 static PyMemberDef __pyx_CyFunction_members[] = {
    406     {(char *) "__module__", T_OBJECT, offsetof(__pyx_CyFunctionObject, func.m_module), PY_WRITE_RESTRICTED, 0},
    407     {0, 0, 0,  0, 0}
    408 };
    409 
    410 static PyObject *
    411 __Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, CYTHON_UNUSED PyObject *args)
    412 {
    413 #if PY_MAJOR_VERSION >= 3
    414     return PyUnicode_FromString(m->func.m_ml->ml_name);
    415 #else
    416     return PyString_FromString(m->func.m_ml->ml_name);
    417 #endif
    418 }
    419 
    420 static PyMethodDef __pyx_CyFunction_methods[] = {
    421     {__Pyx_NAMESTR("__reduce__"), (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    422     {0, 0, 0, 0}
    423 };
    424 
    425 
    426 static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
    427                                       PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    428     __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
    429     if (op == NULL)
    430         return NULL;
    431     op->flags = flags;
    432     op->func_weakreflist = NULL;
    433     op->func.m_ml = ml;
    434     op->func.m_self = (PyObject *) op;
    435     Py_XINCREF(closure);
    436     op->func_closure = closure;
    437     Py_XINCREF(module);
    438     op->func.m_module = module;
    439     op->func_dict = NULL;
    440     op->func_name = NULL;
    441     Py_INCREF(qualname);
    442     op->func_qualname = qualname;
    443     op->func_doc = NULL;
    444     op->func_classobj = NULL;
    445     op->func_globals = globals;
    446     Py_INCREF(op->func_globals);
    447     Py_XINCREF(code);
    448     op->func_code = code;
    449     /* Dynamic Default args */
    450     op->defaults_pyobjects = 0;
    451     op->defaults = NULL;
    452     op->defaults_tuple = NULL;
    453     op->defaults_kwdict = NULL;
    454     op->defaults_getter = NULL;
    455     op->func_annotations = NULL;
    456     PyObject_GC_Track(op);
    457     return (PyObject *) op;
    458 }
    459 
    460 static int
    461 __Pyx_CyFunction_clear(__pyx_CyFunctionObject *m)
    462 {
    463     Py_CLEAR(m->func_closure);
    464     Py_CLEAR(m->func.m_module);
    465     Py_CLEAR(m->func_dict);
    466     Py_CLEAR(m->func_name);
    467     Py_CLEAR(m->func_qualname);
    468     Py_CLEAR(m->func_doc);
    469     Py_CLEAR(m->func_globals);
    470     Py_CLEAR(m->func_code);
    471     Py_CLEAR(m->func_classobj);
    472     Py_CLEAR(m->defaults_tuple);
    473     Py_CLEAR(m->defaults_kwdict);
    474     Py_CLEAR(m->func_annotations);
    475 
    476     if (m->defaults) {
    477         PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
    478         int i;
    479 
    480         for (i = 0; i < m->defaults_pyobjects; i++)
    481             Py_XDECREF(pydefaults[i]);
    482 
    483         PyMem_Free(m->defaults);
    484         m->defaults = NULL;
    485     }
    486 
    487     return 0;
    488 }
    489 
    490 static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
    491 {
    492     PyObject_GC_UnTrack(m);
    493     if (m->func_weakreflist != NULL)
    494         PyObject_ClearWeakRefs((PyObject *) m);
    495     __Pyx_CyFunction_clear(m);
    496     PyObject_GC_Del(m);
    497 }
    498 
    499 static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg)
    500 {
    501     Py_VISIT(m->func_closure);
    502     Py_VISIT(m->func.m_module);
    503     Py_VISIT(m->func_dict);
    504     Py_VISIT(m->func_name);
    505     Py_VISIT(m->func_qualname);
    506     Py_VISIT(m->func_doc);
    507     Py_VISIT(m->func_globals);
    508     Py_VISIT(m->func_code);
    509     Py_VISIT(m->func_classobj);
    510     Py_VISIT(m->defaults_tuple);
    511     Py_VISIT(m->defaults_kwdict);
    512 
    513     if (m->defaults) {
    514         PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
    515         int i;
    516 
    517         for (i = 0; i < m->defaults_pyobjects; i++)
    518             Py_VISIT(pydefaults[i]);
    519     }
    520 
    521     return 0;
    522 }
    523 
    524 static PyObject *__Pyx_CyFunction_descr_get(PyObject *func, PyObject *obj, PyObject *type)
    525 {
    526     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    527 
    528     if (m->flags & __Pyx_CYFUNCTION_STATICMETHOD) {
    529         Py_INCREF(func);
    530         return func;
    531     }
    532 
    533     if (m->flags & __Pyx_CYFUNCTION_CLASSMETHOD) {
    534         if (type == NULL)
    535             type = (PyObject *)(Py_TYPE(obj));
    536         return PyMethod_New(func,
    537                             type, (PyObject *)(Py_TYPE(type)));
    538     }
    539 
    540     if (obj == Py_None)
    541         obj = NULL;
    542     return PyMethod_New(func, obj, type);
    543 }
    544 
    545 static PyObject*
    546 __Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
    547 {
    548 #if PY_MAJOR_VERSION >= 3
    549     return PyUnicode_FromFormat("<cyfunction %U at %p>",
    550                                 op->func_qualname, (void *)op);
    551 #else
    552     return PyString_FromFormat("<cyfunction %s at %p>",
    553                                PyString_AsString(op->func_qualname), (void *)op);
    554 #endif
    555 }
    556 
    557 #if CYTHON_COMPILING_IN_PYPY
    558 /* originally copied from PyCFunction_Call() in CPython's Objects/methodobject.c */
    559 /* PyPy does not have this function */
    560 static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    561     PyCFunctionObject* f = (PyCFunctionObject*)func;
    562     PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    563     PyObject *self = PyCFunction_GET_SELF(func);
    564     Py_ssize_t size;
    565 
    566     switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
    567     case METH_VARARGS:
    568         if (likely(kw == NULL) || PyDict_Size(kw) == 0)
    569             return (*meth)(self, arg);
    570         break;
    571     case METH_VARARGS | METH_KEYWORDS:
    572         return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
    573     case METH_NOARGS:
    574         if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
    575             size = PyTuple_GET_SIZE(arg);
    576             if (size == 0)
    577                 return (*meth)(self, NULL);
    578             PyErr_Format(PyExc_TypeError,
    579                 "%.200s() takes no arguments (%zd given)",
    580                 f->m_ml->ml_name, size);
    581             return NULL;
    582         }
    583         break;
    584     case METH_O:
    585         if (likely(kw == NULL) || PyDict_Size(kw) == 0) {
    586             size = PyTuple_GET_SIZE(arg);
    587             if (size == 1)
    588                 return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
    589             PyErr_Format(PyExc_TypeError,
    590                 "%.200s() takes exactly one argument (%zd given)",
    591                 f->m_ml->ml_name, size);
    592             return NULL;
    593         }
    594         break;
    595     default:
    596         PyErr_SetString(PyExc_SystemError, "Bad call flags in "
    597                         "__Pyx_CyFunction_Call. METH_OLDARGS is no "
    598                         "longer supported!");
    599 
    600         return NULL;
    601     }
    602     PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments",
    603                  f->m_ml->ml_name);
    604     return NULL;
    605 }
    606 #else
    607 static PyObject * __Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    608 	return PyCFunction_Call(func, arg, kw);
    609 }
    610 #endif
    611 
    612 static PyTypeObject __pyx_CyFunctionType_type = {
    613     PyVarObject_HEAD_INIT(0, 0)
    614     __Pyx_NAMESTR("cython_function_or_method"), /*tp_name*/
    615     sizeof(__pyx_CyFunctionObject),   /*tp_basicsize*/
    616     0,                                  /*tp_itemsize*/
    617     (destructor) __Pyx_CyFunction_dealloc, /*tp_dealloc*/
    618     0,                                  /*tp_print*/
    619     0,                                  /*tp_getattr*/
    620     0,                                  /*tp_setattr*/
    621 #if PY_MAJOR_VERSION < 3
    622     0,                                  /*tp_compare*/
    623 #else
    624     0,                                  /*reserved*/
    625 #endif
    626     (reprfunc) __Pyx_CyFunction_repr,   /*tp_repr*/
    627     0,                                  /*tp_as_number*/
    628     0,                                  /*tp_as_sequence*/
    629     0,                                  /*tp_as_mapping*/
    630     0,                                  /*tp_hash*/
    631     __Pyx_CyFunction_Call,              /*tp_call*/
    632     0,                                  /*tp_str*/
    633     0,                                  /*tp_getattro*/
    634     0,                                  /*tp_setattro*/
    635     0,                                  /*tp_as_buffer*/
    636     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags*/
    637     0,                                  /*tp_doc*/
    638     (traverseproc) __Pyx_CyFunction_traverse,   /*tp_traverse*/
    639     (inquiry) __Pyx_CyFunction_clear,   /*tp_clear*/
    640     0,                                  /*tp_richcompare*/
    641     offsetof(__pyx_CyFunctionObject, func_weakreflist), /* tp_weaklistoffse */
    642     0,                                  /*tp_iter*/
    643     0,                                  /*tp_iternext*/
    644     __pyx_CyFunction_methods,           /*tp_methods*/
    645     __pyx_CyFunction_members,           /*tp_members*/
    646     __pyx_CyFunction_getsets,           /*tp_getset*/
    647     0,                                  /*tp_base*/
    648     0,                                  /*tp_dict*/
    649     __Pyx_CyFunction_descr_get,         /*tp_descr_get*/
    650     0,                                  /*tp_descr_set*/
    651     offsetof(__pyx_CyFunctionObject, func_dict),/*tp_dictoffset*/
    652     0,                                  /*tp_init*/
    653     0,                                  /*tp_alloc*/
    654     0,                                  /*tp_new*/
    655     0,                                  /*tp_free*/
    656     0,                                  /*tp_is_gc*/
    657     0,                                  /*tp_bases*/
    658     0,                                  /*tp_mro*/
    659     0,                                  /*tp_cache*/
    660     0,                                  /*tp_subclasses*/
    661     0,                                  /*tp_weaklist*/
    662     0,                                  /*tp_del*/
    663 #if PY_VERSION_HEX >= 0x02060000
    664     0,                                  /*tp_version_tag*/
    665 #endif
    666 #if PY_VERSION_HEX >= 0x030400a1
    667     0,                                  /*tp_finalize*/
    668 #endif
    669 };
    670 
    671 
    672 static int __Pyx_CyFunction_init(void) {
    673 #if !CYTHON_COMPILING_IN_PYPY
    674     // avoid a useless level of call indirection
    675     __pyx_CyFunctionType_type.tp_call = PyCFunction_Call;
    676 #endif
    677     __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    678     if (__pyx_CyFunctionType == NULL) {
    679         return -1;
    680     }
    681     return 0;
    682 }
    683 
    684 static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    685     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    686 
    687     m->defaults = PyMem_Malloc(size);
    688     if (!m->defaults)
    689         return PyErr_NoMemory();
    690     memset(m->defaults, 0, size);
    691     m->defaults_pyobjects = pyobjects;
    692     return m->defaults;
    693 }
    694 
    695 static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) {
    696     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    697     m->defaults_tuple = tuple;
    698     Py_INCREF(tuple);
    699 }
    700 
    701 static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    702     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    703     m->defaults_kwdict = dict;
    704     Py_INCREF(dict);
    705 }
    706 
    707 static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    708     __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    709     m->func_annotations = dict;
    710     Py_INCREF(dict);
    711 }
    712 
    713 //////////////////// CyFunctionClassCell.proto ////////////////////
    714 static CYTHON_INLINE void __Pyx_CyFunction_InitClassCell(PyObject *cyfunctions,
    715                                                          PyObject *classobj);
    716 
    717 //////////////////// CyFunctionClassCell ////////////////////
    718 //@requires: CythonFunction
    719 
    720 static CYTHON_INLINE void __Pyx_CyFunction_InitClassCell(PyObject *cyfunctions, PyObject *classobj) {
    721     int i;
    722 
    723     for (i = 0; i < PyList_GET_SIZE(cyfunctions); i++) {
    724         __pyx_CyFunctionObject *m =
    725             (__pyx_CyFunctionObject *) PyList_GET_ITEM(cyfunctions, i);
    726         m->func_classobj = classobj;
    727         Py_INCREF(classobj);
    728     }
    729 }
    730 
    731 //////////////////// FusedFunction.proto ////////////////////
    732 typedef struct {
    733     __pyx_CyFunctionObject func;
    734     PyObject *__signatures__;
    735     PyObject *type;
    736     PyObject *self;
    737 } __pyx_FusedFunctionObject;
    738 
    739 #define __pyx_FusedFunction_NewEx(ml, flags, qualname, self, module, globals, code)         \
    740         __pyx_FusedFunction_New(__pyx_FusedFunctionType, ml, flags, qualname, self, module, globals, code)
    741 static PyObject *__pyx_FusedFunction_New(PyTypeObject *type,
    742                                          PyMethodDef *ml, int flags,
    743                                          PyObject *qualname, PyObject *self,
    744                                          PyObject *module, PyObject *globals,
    745                                          PyObject *code);
    746 
    747 static int __pyx_FusedFunction_clear(__pyx_FusedFunctionObject *self);
    748 static PyTypeObject *__pyx_FusedFunctionType = NULL;
    749 static int __pyx_FusedFunction_init(void);
    750 
    751 #define __Pyx_FusedFunction_USED
    752 
    753 //////////////////// FusedFunction ////////////////////
    754 //@requires: CythonFunction
    755 
    756 static PyObject *
    757 __pyx_FusedFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags,
    758                         PyObject *qualname, PyObject *self,
    759                         PyObject *module, PyObject *globals,
    760                         PyObject *code)
    761 {
    762     __pyx_FusedFunctionObject *fusedfunc =
    763         (__pyx_FusedFunctionObject *) __Pyx_CyFunction_New(type, ml, flags, qualname,
    764                                                            self, module, globals, code);
    765     if (!fusedfunc)
    766         return NULL;
    767 
    768     fusedfunc->__signatures__ = NULL;
    769     fusedfunc->type = NULL;
    770     fusedfunc->self = NULL;
    771     return (PyObject *) fusedfunc;
    772 }
    773 
    774 static void __pyx_FusedFunction_dealloc(__pyx_FusedFunctionObject *self) {
    775     __pyx_FusedFunction_clear(self);
    776     __pyx_FusedFunctionType->tp_free((PyObject *) self);
    777 }
    778 
    779 static int
    780 __pyx_FusedFunction_traverse(__pyx_FusedFunctionObject *self,
    781                              visitproc visit,
    782                              void *arg)
    783 {
    784     Py_VISIT(self->self);
    785     Py_VISIT(self->type);
    786     Py_VISIT(self->__signatures__);
    787     return __Pyx_CyFunction_traverse((__pyx_CyFunctionObject *) self, visit, arg);
    788 }
    789 
    790 static int
    791 __pyx_FusedFunction_clear(__pyx_FusedFunctionObject *self)
    792 {
    793     Py_CLEAR(self->self);
    794     Py_CLEAR(self->type);
    795     Py_CLEAR(self->__signatures__);
    796     return __Pyx_CyFunction_clear((__pyx_CyFunctionObject *) self);
    797 }
    798 
    799 
    800 static PyObject *
    801 __pyx_FusedFunction_descr_get(PyObject *self, PyObject *obj, PyObject *type)
    802 {
    803     __pyx_FusedFunctionObject *func, *meth;
    804 
    805     func = (__pyx_FusedFunctionObject *) self;
    806 
    807     if (func->self || func->func.flags & __Pyx_CYFUNCTION_STATICMETHOD) {
    808         /* Do not allow rebinding and don't do anything for static methods */
    809         Py_INCREF(self);
    810         return self;
    811     }
    812 
    813     if (obj == Py_None)
    814         obj = NULL;
    815 
    816     meth = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_NewEx(
    817                     ((PyCFunctionObject *) func)->m_ml,
    818                     ((__pyx_CyFunctionObject *) func)->flags,
    819                     ((__pyx_CyFunctionObject *) func)->func_qualname,
    820                     ((__pyx_CyFunctionObject *) func)->func_closure,
    821                     ((PyCFunctionObject *) func)->m_module,
    822                     ((__pyx_CyFunctionObject *) func)->func_globals,
    823                     ((__pyx_CyFunctionObject *) func)->func_code);
    824     if (!meth)
    825         return NULL;
    826 
    827     Py_XINCREF(func->func.func_classobj);
    828     meth->func.func_classobj = func->func.func_classobj;
    829 
    830     Py_XINCREF(func->__signatures__);
    831     meth->__signatures__ = func->__signatures__;
    832 
    833     Py_XINCREF(type);
    834     meth->type = type;
    835 
    836     Py_XINCREF(func->func.defaults_tuple);
    837     meth->func.defaults_tuple = func->func.defaults_tuple;
    838 
    839     if (func->func.flags & __Pyx_CYFUNCTION_CLASSMETHOD)
    840         obj = type;
    841 
    842     Py_XINCREF(obj);
    843     meth->self = obj;
    844 
    845     return (PyObject *) meth;
    846 }
    847 
    848 static PyObject *
    849 _obj_to_str(PyObject *obj)
    850 {
    851     if (PyType_Check(obj))
    852         return PyObject_GetAttr(obj, PYIDENT("__name__"));
    853     else
    854         return PyObject_Str(obj);
    855 }
    856 
    857 static PyObject *
    858 __pyx_FusedFunction_getitem(__pyx_FusedFunctionObject *self, PyObject *idx)
    859 {
    860     PyObject *signature = NULL;
    861     PyObject *unbound_result_func;
    862     PyObject *result_func = NULL;
    863 
    864     if (self->__signatures__ == NULL) {
    865         PyErr_SetString(PyExc_TypeError, "Function is not fused");
    866         return NULL;
    867     }
    868 
    869     if (PyTuple_Check(idx)) {
    870         PyObject *list = PyList_New(0);
    871         Py_ssize_t n = PyTuple_GET_SIZE(idx);
    872         PyObject *string = NULL;
    873         PyObject *sep = NULL;
    874         int i;
    875 
    876         if (!list)
    877             return NULL;
    878 
    879         for (i = 0; i < n; i++) {
    880             PyObject *item = PyTuple_GET_ITEM(idx, i);
    881 
    882             string = _obj_to_str(item);
    883             if (!string || PyList_Append(list, string) < 0)
    884                 goto __pyx_err;
    885 
    886             Py_DECREF(string);
    887         }
    888 
    889         sep = PyUnicode_FromString("|");
    890         if (sep)
    891             signature = PyUnicode_Join(sep, list);
    892 __pyx_err:
    893 ;
    894         Py_DECREF(list);
    895         Py_XDECREF(sep);
    896     } else {
    897         signature = _obj_to_str(idx);
    898     }
    899 
    900     if (!signature)
    901         return NULL;
    902 
    903     unbound_result_func = PyObject_GetItem(self->__signatures__, signature);
    904 
    905     if (unbound_result_func) {
    906         if (self->self || self->type) {
    907             __pyx_FusedFunctionObject *unbound = (__pyx_FusedFunctionObject *) unbound_result_func;
    908 
    909             /* Todo: move this to InitClassCell */
    910             Py_CLEAR(unbound->func.func_classobj);
    911             Py_XINCREF(self->func.func_classobj);
    912             unbound->func.func_classobj = self->func.func_classobj;
    913 
    914             result_func = __pyx_FusedFunction_descr_get(unbound_result_func,
    915                                                         self->self, self->type);
    916         } else {
    917             result_func = unbound_result_func;
    918             Py_INCREF(result_func);
    919         }
    920     }
    921 
    922     Py_DECREF(signature);
    923     Py_XDECREF(unbound_result_func);
    924 
    925     return result_func;
    926 }
    927 
    928 static PyObject *
    929 __pyx_FusedFunction_callfunction(PyObject *func, PyObject *args, PyObject *kw)
    930 {
    931      __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
    932     PyObject *result;
    933     int static_specialized = (cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD &&
    934                               !((__pyx_FusedFunctionObject *) func)->__signatures__);
    935 
    936     if (cyfunc->flags & __Pyx_CYFUNCTION_CCLASS && !static_specialized) {
    937         Py_ssize_t argc;
    938         PyObject *new_args;
    939         PyObject *self;
    940         PyObject *m_self;
    941 
    942         argc = PyTuple_GET_SIZE(args);
    943         new_args = PyTuple_GetSlice(args, 1, argc);
    944 
    945         if (!new_args)
    946             return NULL;
    947 
    948         self = PyTuple_GetItem(args, 0);
    949 
    950         if (!self)
    951             return NULL;
    952 
    953         m_self = cyfunc->func.m_self;
    954         cyfunc->func.m_self = self;
    955         result = __Pyx_CyFunction_Call(func, new_args, kw);
    956         cyfunc->func.m_self = m_self;
    957 
    958         Py_DECREF(new_args);
    959     } else {
    960         result = __Pyx_CyFunction_Call(func, args, kw);
    961     }
    962 
    963     return result;
    964 }
    965 
    966 /* Note: the 'self' from method binding is passed in in the args tuple,
    967          whereas PyCFunctionObject's m_self is passed in as the first
    968          argument to the C function. For extension methods we need
    969          to pass 'self' as 'm_self' and not as the first element of the
    970          args tuple.
    971 */
    972 static PyObject *
    973 __pyx_FusedFunction_call(PyObject *func, PyObject *args, PyObject *kw)
    974 {
    975     __pyx_FusedFunctionObject *binding_func = (__pyx_FusedFunctionObject *) func;
    976     Py_ssize_t argc = PyTuple_GET_SIZE(args);
    977     PyObject *new_args = NULL;
    978     __pyx_FusedFunctionObject *new_func = NULL;
    979     PyObject *result = NULL;
    980     PyObject *self = NULL;
    981     int is_staticmethod = binding_func->func.flags & __Pyx_CYFUNCTION_STATICMETHOD;
    982     int is_classmethod = binding_func->func.flags & __Pyx_CYFUNCTION_CLASSMETHOD;
    983 
    984     if (binding_func->self) {
    985         /* Bound method call, put 'self' in the args tuple */
    986         Py_ssize_t i;
    987         new_args = PyTuple_New(argc + 1);
    988         if (!new_args)
    989             return NULL;
    990 
    991         self = binding_func->self;
    992         Py_INCREF(self);
    993         PyTuple_SET_ITEM(new_args, 0, self);
    994 
    995         for (i = 0; i < argc; i++) {
    996             PyObject *item = PyTuple_GET_ITEM(args, i);
    997             Py_INCREF(item);
    998             PyTuple_SET_ITEM(new_args, i + 1, item);
    999         }
   1000 
   1001         args = new_args;
   1002     } else if (binding_func->type) {
   1003         /* Unbound method call */
   1004         if (argc < 1) {
   1005             PyErr_SetString(PyExc_TypeError, "Need at least one argument, 0 given.");
   1006             return NULL;
   1007         }
   1008         self = PyTuple_GET_ITEM(args, 0);
   1009     }
   1010 
   1011     if (self && !is_classmethod && !is_staticmethod &&
   1012             !PyObject_IsInstance(self, binding_func->type)) {
   1013         PyErr_Format(PyExc_TypeError,
   1014                      "First argument should be of type %.200s, got %.200s.",
   1015                      ((PyTypeObject *) binding_func->type)->tp_name,
   1016                      self->ob_type->tp_name);
   1017         goto __pyx_err;
   1018     }
   1019 
   1020     if (binding_func->__signatures__) {
   1021         PyObject *tup = PyTuple_Pack(4, binding_func->__signatures__, args,
   1022                                         kw == NULL ? Py_None : kw,
   1023                                         binding_func->func.defaults_tuple);
   1024         if (!tup)
   1025             goto __pyx_err;
   1026 
   1027         new_func = (__pyx_FusedFunctionObject *) __pyx_FusedFunction_callfunction(func, tup, NULL);
   1028         Py_DECREF(tup);
   1029 
   1030         if (!new_func)
   1031             goto __pyx_err;
   1032 
   1033         Py_XINCREF(binding_func->func.func_classobj);
   1034         Py_CLEAR(new_func->func.func_classobj);
   1035         new_func->func.func_classobj = binding_func->func.func_classobj;
   1036 
   1037         func = (PyObject *) new_func;
   1038     }
   1039 
   1040     result = __pyx_FusedFunction_callfunction(func, args, kw);
   1041 __pyx_err:
   1042     Py_XDECREF(new_args);
   1043     Py_XDECREF((PyObject *) new_func);
   1044     return result;
   1045 }
   1046 
   1047 static PyMemberDef __pyx_FusedFunction_members[] = {
   1048     {(char *) "__signatures__",
   1049      T_OBJECT,
   1050      offsetof(__pyx_FusedFunctionObject, __signatures__),
   1051      READONLY,
   1052      __Pyx_DOCSTR(0)},
   1053     {0, 0, 0, 0, 0},
   1054 };
   1055 
   1056 static PyMappingMethods __pyx_FusedFunction_mapping_methods = {
   1057     0,
   1058     (binaryfunc) __pyx_FusedFunction_getitem,
   1059     0,
   1060 };
   1061 
   1062 static PyTypeObject __pyx_FusedFunctionType_type = {
   1063     PyVarObject_HEAD_INIT(0, 0)
   1064     __Pyx_NAMESTR("fused_cython_function"), /*tp_name*/
   1065     sizeof(__pyx_FusedFunctionObject), /*tp_basicsize*/
   1066     0,                                  /*tp_itemsize*/
   1067     (destructor) __pyx_FusedFunction_dealloc, /*tp_dealloc*/
   1068     0,                                  /*tp_print*/
   1069     0,                                  /*tp_getattr*/
   1070     0,                                  /*tp_setattr*/
   1071 #if PY_MAJOR_VERSION < 3
   1072     0,                                  /*tp_compare*/
   1073 #else
   1074     0,                                  /*reserved*/
   1075 #endif
   1076     0,                                  /*tp_repr*/
   1077     0,                                  /*tp_as_number*/
   1078     0,                                  /*tp_as_sequence*/
   1079     &__pyx_FusedFunction_mapping_methods, /*tp_as_mapping*/
   1080     0,                                  /*tp_hash*/
   1081     (ternaryfunc) __pyx_FusedFunction_call, /*tp_call*/
   1082     0,                                  /*tp_str*/
   1083     0,                                  /*tp_getattro*/
   1084     0,                                  /*tp_setattro*/
   1085     0,                                  /*tp_as_buffer*/
   1086     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /* tp_flags*/
   1087     0,                                  /*tp_doc*/
   1088     (traverseproc) __pyx_FusedFunction_traverse,   /*tp_traverse*/
   1089     (inquiry) __pyx_FusedFunction_clear,/*tp_clear*/
   1090     0,                                  /*tp_richcompare*/
   1091     0,                                  /*tp_weaklistoffset*/
   1092     0,                                  /*tp_iter*/
   1093     0,                                  /*tp_iternext*/
   1094     0,                                  /*tp_methods*/
   1095     __pyx_FusedFunction_members,        /*tp_members*/
   1096     /* __doc__ is None for the fused function type, but we need it to be */
   1097     /* a descriptor for the instance's __doc__, so rebuild descriptors in our subclass */
   1098     __pyx_CyFunction_getsets,           /*tp_getset*/
   1099     &__pyx_CyFunctionType_type,         /*tp_base*/
   1100     0,                                  /*tp_dict*/
   1101     __pyx_FusedFunction_descr_get,      /*tp_descr_get*/
   1102     0,                                  /*tp_descr_set*/
   1103     0,                                  /*tp_dictoffset*/
   1104     0,                                  /*tp_init*/
   1105     0,                                  /*tp_alloc*/
   1106     0,                                  /*tp_new*/
   1107     0,                                  /*tp_free*/
   1108     0,                                  /*tp_is_gc*/
   1109     0,                                  /*tp_bases*/
   1110     0,                                  /*tp_mro*/
   1111     0,                                  /*tp_cache*/
   1112     0,                                  /*tp_subclasses*/
   1113     0,                                  /*tp_weaklist*/
   1114     0,                                  /*tp_del*/
   1115 #if PY_VERSION_HEX >= 0x02060000
   1116     0,                                  /*tp_version_tag*/
   1117 #endif
   1118 #if PY_VERSION_HEX >= 0x030400a1
   1119     0,                                  /*tp_finalize*/
   1120 #endif
   1121 };
   1122 
   1123 static int __pyx_FusedFunction_init(void) {
   1124     __pyx_FusedFunctionType = __Pyx_FetchCommonType(&__pyx_FusedFunctionType_type);
   1125     if (__pyx_FusedFunctionType == NULL) {
   1126         return -1;
   1127     }
   1128     return 0;
   1129 }
   1130 
   1131 //////////////////// ClassMethod.proto ////////////////////
   1132 
   1133 #include "descrobject.h"
   1134 static PyObject* __Pyx_Method_ClassMethod(PyObject *method); /*proto*/
   1135 
   1136 //////////////////// ClassMethod ////////////////////
   1137 
   1138 static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
   1139 #if CYTHON_COMPILING_IN_PYPY
   1140     if (PyObject_TypeCheck(method, &PyWrapperDescr_Type)) { /* cdef classes */
   1141         return PyClassMethod_New(method);
   1142     }
   1143 #else
   1144     /* It appears that PyMethodDescr_Type is not anywhere exposed in the Python/C API */
   1145     static PyTypeObject *methoddescr_type = NULL;
   1146     if (methoddescr_type == NULL) {
   1147        PyObject *meth = __Pyx_GetAttrString((PyObject*)&PyList_Type, "append");
   1148        if (!meth) return NULL;
   1149        methoddescr_type = Py_TYPE(meth);
   1150        Py_DECREF(meth);
   1151     }
   1152     if (PyObject_TypeCheck(method, methoddescr_type)) { /* cdef classes */
   1153         PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
   1154         #if PY_VERSION_HEX < 0x03020000
   1155         PyTypeObject *d_type = descr->d_type;
   1156         #else
   1157         PyTypeObject *d_type = descr->d_common.d_type;
   1158         #endif
   1159         return PyDescr_NewClassMethod(d_type, descr->d_method);
   1160     }
   1161 #endif
   1162     else if (PyMethod_Check(method)) { /* python classes */
   1163         return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
   1164     }
   1165     else if (PyCFunction_Check(method)) {
   1166         return PyClassMethod_New(method);
   1167     }
   1168 #ifdef __Pyx_CyFunction_USED
   1169     else if (PyObject_TypeCheck(method, __pyx_CyFunctionType)) {
   1170         return PyClassMethod_New(method);
   1171     }
   1172 #endif
   1173     PyErr_SetString(PyExc_TypeError,
   1174                    "Class-level classmethod() can only be called on "
   1175                    "a method_descriptor or instance method.");
   1176     return NULL;
   1177 }
   1178