You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 5, 2023. It is now read-only.
Expose more information about function line numbers #50
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.
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.
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?
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.
Activity
gvanrossum commentedon Aug 25, 2017
Whatever solution we pick should also be applied to decorated classes.
emmatyping commentedon Aug 25, 2017
In python/mypy#3871 we seem to be of the opinion that adding
class_linenoanddef_linenoattributes are the best solution.emmatyping commentedon Aug 25, 2017
To be clear, I am adding this to
ClassDef,FunctionDef, andAsyncFunctionDef.emmatyping commentedon 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 commentedon Nov 22, 2018
Taking into account size of the fix, can we backport just the fix now? Supporting 3.7 in
typed_astmay take time because of theASYNCproblems, while this fix looks small and well localized.emmatyping commentedon Nov 23, 2018
Sure, I'd be happy to make a PR.
ilevkivskyi commentedon Nov 23, 2018
OK, let's do this then.
gvanrossum commentedon Apr 28, 2019
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: ignorecomments would have to go. So maybe let sleeping dogs lie?gvanrossum commentedon Apr 29, 2019
Let's leave typed_ast alone. With Python 3.8 we can support
# type: ignorebackward compatibility, see python/mypy#3871 (comment) and further comments. For 3.7 and before we'll stick with the status quo.Merge pull request python#50 from python-lz4/py2bytearray