question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generate Python typing compatible text signatures (and stubs)

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
scodercommented, 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.

1reaction
cmputecommented, Jul 30, 2020

Looking forward to this functionality! I usually write all documentation in .pyx files, so it could be very nice to have automatic .pyi generation!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found