Skip to content

"# type: ignore" does not seem to work on multiline dicts #627

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
josephharrington opened this issue Mar 30, 2015 · 3 comments
Closed

"# type: ignore" does not seem to work on multiline dicts #627

josephharrington opened this issue Mar 30, 2015 · 3 comments
Labels
bug mypy got something wrong

Comments

@josephharrington
Copy link

There seems to be inconsistent behavior between these two equivalent pieces of code.

mypy is happy with this:

import http.client
errors = {'not_found': http.client.NOT_FOUND}  # type: ignore

but this fails with "module" has no attribute "NOT_FOUND" (no matter where I put the annotation):

import http.client
errors = {                              # type: ignore
    'not_found': http.client.NOT_FOUND  # type: ignore
}                                       # type: ignore
@JukkaL JukkaL added bug mypy got something wrong priority labels Mar 31, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 31, 2015

Thanks for reporting this! I think the reason is that mypy only recognizes ignore annotations on the last line of a statement, which is clearly broken.

I think that there are also some other cases where # type: ignore might not work correctly. The feature is still going to need a bit more love :-) If you spot any other cases where it behaves strangely, please report them since this is a pretty important feature.

@JukkaL JukkaL closed this as completed in aaa3752 Apr 5, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Apr 5, 2015

Your example should now work like this:

import http.client
errors = {
    'not_found': http.client.NOT_FOUND  # type: ignore
} 

The # type: ignore comment should be put on the line that the error refers to. This way we can only ignore parts of a multi-line statement, which can be useful in cases such as large dict literals.

@gvanrossum
Copy link
Member

Do you think we should specify this in the PEP? Or is this a mypy "extra"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants