-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stubgen and Cython modules #7542
Comments
Stubgen support for Cython modules would be nice. Would you like to create a PR? If you have questions, feel free to ask them here. (And apologies for the slow response.) |
Both interesting and nice feature to have and I'd like to take a shot |
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
I decided to take a stab at this issue - see PR #8631 and lmk feedback, thanks! |
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Minimal support for Cython functions in stubgen for generating .pyi files from a C module. Based on python#7542.
Are you able to run
It appears |
@matteosantama I was running stubgen on the compiled extension module, not on the .pyx source code. |
Bump |
Hello,
I'm trying to use mypy with a Cython module (via stubgen).
Example Cython module:
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.#cython: binding=True
: Cython will use a custom function object (not aPyCFunction
) that has the relevant attributes set -- this allows usinginspect.signature()
.The
embedsignature
approach has some problems that I think are on the Cython side of things, see cython/cython#3150.For the
binding
approach, stubgen currently outputs:Both
f
andMyClass.run
are of typecyfunction
, which does not match this test for a C function:The
cyfunction
is effectively a custom callable that has most of the attributes expected for a function:The
str
->unicode
replacement is a Cython bug, but that can be worked around by defining aunicode = str
type alias.To allow using mypy for a project that imports Cython libraries, I think stubgen should:
cyfunction
as a function and emit a function declaration based oninspect.signature()
cyfunction
and useinspect.signature()
instead of relying on the docstringThe text was updated successfully, but these errors were encountered: