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
Support for Python 2/3 "straddling" type hint comments #2755
Comments
👍 |
I made a start on extracting type comments in another project, could be useful as a starting point for you: https://github.com/dls-controls/annotypes/blob/master/annotypes/_calltypes.py#L81 I only attempt to parse comments where they exactly match the number of arguments given to the function, otherwise ast parsing would have been required rather than just tokenizing and comparing the type strings with the arguments of the function... |
EOL of python2 will come soon. So I feel this issue become less important now. In addition, we don't have enough time to implement this. So I'd like to mark this as "wontfix". |
Note: About .pyi file support, we are discussing in #4824. |
I think this is partially handled by master of https://github.com/agronholm/sphinx-autodoc-typehints |
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Since python 3.8, typed_ast is merged into python core as 'ast.parse(..., type_comment=True)`. |
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Note: python3.8+ or typed_ast is required
Close #2755: autodoc: Support type_comment style annotation
Many libraries will likely maintain Python 2 compatibility for some time yet. It would be fantastic if Sphinx apidoc supported the Python 2.7-friendly "straddling" syntax for type hints that was added to PEP 484 (i.e.
# type:
comments), for rendering in the same way as Python 3 type hints currently do. Additionally, support for.pyi
files could also help for similar use cases.PyCharm supports the
# type:
comments now, so demand might increase from people maintaining Python 2-compatible code.I'm not at all familiar with Sphinx internals but I could try to work on this with a bit of guidance, perhaps.
Note that GvR directed me to dropbox/typed_ast for getting at the information, urging not to try to use mypy as a library due to instability of its API. typed_ast supports parsing Python 2.7 code but unfortunately itself only runs in Python 3.
The text was updated successfully, but these errors were encountered: