Generate Python typing compatible text signatures (and stubs)
See original GitHub issueMy .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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
typing — Support for type hints — Python 3.11.1 documentation
At runtime, the statement Derived = NewType('Derived', Base) will make Derived a callable that immediately returns whatever parameter you pass it. That means ......
Read more >typing — Support for type hints — Python 3.7.14 documentation
Type aliases are useful for simplifying complex type signatures. ... Use the NewType() helper function to create distinct types: from typing ...
Read more >PEP 484 – Type Hints - Python Enhancement Proposals
This PEP aims to provide a standard syntax for type annotations, opening up Python code to easier static analysis and refactoring, potential runtime...
Read more >PEP 677 – Callable Type Syntax
In Python we have type annotations, the framework for which is defined in PEP 484, to provide type hints that can find bugs...
Read more >PEP 692 – Using TypedDict for more precise **kwargs typing
Keyword collisions · TypedDict that is used to type · **kwargs could potentially contain keys that are already defined in the function's signature...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If generating
.pyi
stubs is not too complex, Cython could do it automatically, yes, similar to how it now generates the embedded signatures inAutoDocTransform
. PR welcome.I also agree that generating ‘normal’ Py3 annotations would be nicer than generating Cython syntax. PR welcome for that, too.
Looking forward to this functionality! I usually write all documentation in
.pyx
files, so it could be very nice to have automatic.pyi
generation!