Closed ethanhs closed 5 years ago
Whatever solution we pick should also be applied to decorated classes.
In https://github.com/python/mypy/issues/3871 we seem to be of the opinion that adding class_lineno
and def_lineno
attributes are the best solution.
To be clear, I am adding this to ClassDef
, FunctionDef
, and AsyncFunctionDef
.
It appears this was fixed in https://github.com/python/cpython/pull/9731. Perhaps we could backport that change after the update to being based on the 3.7 ast?
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.
Sure, I'd be happy to make a PR.
OK, let's do this then.
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 https://github.com/python/mypy/issues/3871#issuecomment-487427583 and further comments. For 3.7 and before we'll stick with the status quo.
In hopes of solving https://github.com/python/mypy/issues/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 havereturns
asNone
, which means mypy cannot get the line number of where the return type annotation should be. Additionally the actualdef
line number may be impossible to calculate based on given ast data.