Skip to content

Generate Python typing compatible text signatures (and stubs) #3150

@dgrunwald

Description

@dgrunwald

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions