Skip to content

Error in type comment points to wrong line #7472

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

Closed
JukkaL opened this issue Sep 5, 2019 · 7 comments
Closed

Error in type comment points to wrong line #7472

JukkaL opened this issue Sep 5, 2019 · 7 comments

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 5, 2019

This fragment generates an error on the line @deco which is confusing:

def deco(x): return x

@deco   # Error: Name 'bad' is not defined
def f(y):
    # type: (bad) -> None
    pass
@emmatyping
Copy link
Member

This is an instance of #3871. I tested on 3.8 and with the better source information, it was able to correctly report the error on the function declaration line.

Perhaps we should document this?

@ilevkivskyi
Copy link
Member

Perhaps we should document this?

It probably makes sense to add a short item in Common issues explaining that type errors may rarely appear in strange locations, and # type: ignore must be placed exactly there.

@JukkaL
Copy link
Collaborator Author

JukkaL commented Sep 6, 2019

Even in 3.8 the error points to the line def f(y):, but it would be better if we can somehow make it point to the type comment line. This may require some hacks if the AST doesn't contain information about the line of the type comment, but it may be worth it.

@AlexWaygood
Copy link
Member

AlexWaygood commented Apr 3, 2022

I'm changing the priority to "low", since type comments are rarely used in modern Python (parameter and variable annotations are generally preferred).

@JelleZijlstra
Copy link
Member

Maybe we should just deprecate type comment support.

@emmatyping
Copy link
Member

I believe type comments are part of PEP 484 so they would need to be deprecated and removed as part of the PEP, there is also the consideration of for/with statements, I've opened a new thread on typing-sig about this https://mail.python.org/archives/list/[email protected]/thread/66JDHQ2I3U3CPUIYA43W7SPEJLLPUETG/

@hauntsaninja
Copy link
Collaborator

This isn't worth fixing

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants