Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Expose more information about function line numbers #50

Closed
ethanhs opened this issue Aug 25, 2017 · 9 comments
Closed

Expose more information about function line numbers #50

ethanhs opened this issue Aug 25, 2017 · 9 comments

Comments

@ethanhs
Copy link
Contributor

ethanhs commented Aug 25, 2017

In hopes of solving python/mypy#3871 we probably need to modify typed_ast to expose more information about function line numbers.

If the return type annotation of a function is absent, the FunctionDef node will have returns as None, which means mypy cannot get the line number of where the return type annotation should be. Additionally the actual def line number may be impossible to calculate based on given ast data.

@gvanrossum
Copy link
Member

Whatever solution we pick should also be applied to decorated classes.

@ethanhs
Copy link
Contributor Author

ethanhs commented Aug 25, 2017

In python/mypy#3871 we seem to be of the opinion that adding class_lineno and def_lineno attributes are the best solution.

@ethanhs
Copy link
Contributor Author

ethanhs commented Aug 25, 2017

To be clear, I am adding this to ClassDef, FunctionDef, and AsyncFunctionDef.

@ethanhs
Copy link
Contributor Author

ethanhs commented Nov 22, 2018

It appears this was fixed in python/cpython#9731. Perhaps we could backport that change after the update to being based on the 3.7 ast?

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Nov 22, 2018

Taking into account size of the fix, can we backport just the fix now? Supporting 3.7 in typed_ast may take time because of the ASYNC problems, while this fix looks small and well localized.

@ethanhs
Copy link
Contributor Author

ethanhs commented Nov 23, 2018

Sure, I'd be happy to make a PR.

@ilevkivskyi
Copy link
Member

OK, let's do this then.

@gvanrossum
Copy link
Member

So... It looks like we took a different path. In Python 3.8's ast this is fixed, but it was not fixed in Python 3.7's ast. Typed_ast is now based on Python 3.7's ast.

Should we do it or not? I worry that just changing the lineno attribute of FunctionDef and ClassDef nodes will break tons of users' code since it changes where # type: ignore comments would have to go. So maybe let sleeping dogs lie?

@gvanrossum
Copy link
Member

Let's leave typed_ast alone. With Python 3.8 we can support # type: ignore backward compatibility, see python/mypy#3871 (comment) and further comments. For 3.7 and before we'll stick with the status quo.

tbbharaj pushed a commit to tbbharaj/typed_ast that referenced this issue Dec 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants