Skip to content
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

Embedded signature uses Cython syntax even if source code does not #3150

dgrunwald opened this issue Sep 20, 2019 · 2 comments


Copy link

commented Sep 20, 2019

My .pyx file uses a PEP-484 style type signature:

#cython: embedsignature=True
def f(path: str, a: int = 0, b: bool = True) -> typing.List[str]:
    return []

Cython 0.29.13 turns this into the docstring:
f(unicode path: str, a: int = 0, bool b: bool = True) -> typing.List[str]
(see also #1370 for "unicode")

When using mypy-stubgen, that docstring turns into:
def f(unicodepath: str, a: int = ..., boolb: bool = ...) -> typing.List[str]: ...

Which causes mypy false positives for Python code calling f with a named argument for b.

I think embedsignature should not output Cython-specific syntax, as that breaks tooling consuming these docstrings.
Ideally it'd also convert Cython signatures into the corresponding Python signatures; but it would be good enough for me if it just left PEP484 signatures as-is.


This comment has been minimized.

Copy link

commented Sep 20, 2019

Alternate ideas:

  • Cython could maybe generate .pyi stubs itself?
  • I could enable binding=True to expose the signature to Python tooling. However the current mypy-stubgen only emits function declarations for what it considers a "C function":
def is_c_function(obj: object) -> bool:
    return inspect.isbuiltin(obj) or type(obj) is type(ord)

so all Cython functions with binding enabled get converted to a simple f: typing.Any. This should probably be fixed on the mypy side.


This comment has been minimized.

Copy link

commented Sep 21, 2019

If generating .pyi stubs is not too complex, Cython could do it automatically, yes, similar to how it now generates the embedded signatures in AutoDocTransform. PR welcome.

I also agree that generating 'normal' Py3 annotations would be nicer than generating Cython syntax. PR welcome for that, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.