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

Support for Python 2/3 "straddling" type hint comments #2755

Closed
ches opened this issue Jul 7, 2016 · 7 comments
Closed

Support for Python 2/3 "straddling" type hint comments #2755

ches opened this issue Jul 7, 2016 · 7 comments
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Milestone

Comments

@ches
Copy link

ches commented Jul 7, 2016

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.

@shimizukawa shimizukawa added extensions:autodoc type:enhancement enhance or introduce a new feature labels Nov 12, 2016
@shimizukawa shimizukawa added this to the 1.6 milestone Nov 12, 2016
@cbornet
Copy link

cbornet commented Jan 20, 2017

👍

@tk0miya tk0miya modified the milestones: 1.7, 1.6 Apr 15, 2017
@shimizukawa shimizukawa modified the milestones: 1.7, 1.8 Jan 7, 2018
@thomascobb
Copy link

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

@Zac-HD
Copy link
Contributor

Zac-HD commented Apr 15, 2018

annotypes permalink

@tk0miya
Copy link
Member

tk0miya commented May 31, 2019

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".
Has anyone tried to implement this? If doing, I can wait for a while.

@tk0miya
Copy link
Member

tk0miya commented May 31, 2019

Note: About .pyi file support, we are discussing in #4824.

@tk0miya tk0miya modified the milestones: 2.1.0, 2.2.0 May 31, 2019
@eric-wieser
Copy link
Contributor

I think this is partially handled by master of https://github.com/agronholm/sphinx-autodoc-typehints

@tk0miya tk0miya modified the milestones: 2.2.0, 2.3.0 Aug 18, 2019
@tk0miya tk0miya modified the milestones: 2.3.0, 2.4.0 Dec 8, 2019
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 1, 2020
@tk0miya
Copy link
Member

tk0miya commented Jan 1, 2020

Since python 3.8, typed_ast is merged into python core as 'ast.parse(..., type_comment=True)`.
So I just created a PR #6982 to support this. Could you try it please?

tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 2, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 11, 2020
tk0miya added a commit that referenced this issue Jan 13, 2020
Close #2755: autodoc: Support type_comment style annotation
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
extensions:autodoc type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

7 participants