You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#cython: binding=True: Cython will use a custom function object (not a PyCFunction) that has the relevant attributes set -- this allows using inspect.signature(). As of Cython 3, this option is enabled by default, and I'll only consider this option in the following.
Both f and MyClass.run are of type cython_function_or_method, which is neither a Python builtin function, nor a PyCFunction.
Instead, it's effectively a custom callable that has most of the attributes expected for a function:
Hello,
I'm trying to use mypy with a Cython module (via stubgen).
Example Cython module (test.pyx):
Compile this module:
cythonize -b test.pyxThe output will be a binary extension module (test..pyd/test..so).
Run stubgen on this via
stubgen -m test.In general, there's two ways in which Cython can expose the function signature:
#cython: embedsignature=True: Cython will embed the signature in the docstring. This has some issues in Cython, see Generate Python typing compatible text signatures (and stubs) cython/cython#3150.#cython: binding=True: Cython will use a custom function object (not aPyCFunction) that has the relevant attributes set -- this allows usinginspect.signature(). As of Cython 3, this option is enabled by default, and I'll only consider this option in the following.Both
fandMyClass.runare of typecython_function_or_method, which is neither a Python builtin function, nor a PyCFunction.Instead, it's effectively a custom callable that has most of the attributes expected for a function:
However stubgen fails to correctly handle this custom callable, and ends creating: