[Cython] inspect.isbuiltin(cyfunction) and inheritance from PyCFunction (was: breaking news in Py3.4: inspect.isfunction(cyfunction) == True)

Stefan Behnel stefan_ml at behnel.de
Sat Feb 1 17:04:19 CET 2014


Stefan Behnel, 31.01.2014 21:01:
> Yury Selivanov just committed a revised version of a patch I wrote for
> CPython's inspect module last year. It now accepts Cython's function type
> as Python function, based on the function-like attributes that it exports.
> 
> http://hg.python.org/cpython/rev/32a660a52aae
> 
> That means that things like inspect.signature(cyfunction) will also work
> now, and finally have a reason to be further improved, including parameter
> introspection, annotations, etc. :)

Sorry, huge correction: inspect.isfunction(cyfunction) still returns False.
Only introspection and signature analysis in the inspect module were
changed. I got it wrong because I had code in my usersitecustomize.py that
monkey patches inspect.isfunction(), and had completely forgotten about it.

Looking through this a bit more, I noticed that CyFunction inherits from
PyCFunction, but doesn't actually tell CPython that it does. If I add this
line to __Pyx_CyFunction_init(), before the PyType_Ready() call:

    __pyx_CyFunctionType_type.tp_base = &PyCFunction_Type;

it still works as expected, but inspect.isbuiltin() now returns True (as
expected). Does anyone see a reason why we should not be doing this?

Stefan



More information about the cython-devel mailing list