-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
type: ignore
needs to be placed partway through a multi-line variable assigment in some cases
#3251
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
Comments
This looks quite similar to #3177, but probably not an exact duplicate. Here it is less clear what is the most obvious line for mypy to report an error. I think the current behaviour is OK. Maybe we should just document some rules for line numbers in errors in multi-line statements/expressions? |
Yeah, this is a known issue, and doesn't just affect assignments. Do you have a specific improvement in mind? It's not obvious to me what would a generally better way to do this. |
I think it's different from #3177. That issue is specifically about everything related to a function heading being attributed to the line where the first decorator starts. This issue is about whether the scope of a type-ignore on a statement that's split across multiple lines should be the entire statement rather than the specific line number on which the type-ignore occurs. I think it's an implementation weakness but it may be hard to fix, since AFAIK the typed_ast parser just gives us line numbers for type-ignores (rather than working them into the parse tree). Either typed_ast or mypy would need a significant re-architecting of the code around type-ignores to fulfill this wish. Also, sometimes it's a useful feature, e.g. when you have a long list of expressions like this:
@ddfisher ^^ |
Yeah, that's the current behavior. That's because type ignores don't really fit into the parse tree in a particularly sensible way -- they're valid anywhere. If this is something we want to fix, changing that is probably not the way forward -- I think it'd be easier to understand the start and end points of statements, and filter errors that way. |
#6648 fixed this, I think. At least for Python 3.8. |
Yup! |
Usually, mypy does this correctly, but today I had to merge zulip/zulip@c4716ae because mypy was
throwingreporting an error (caused by an unrelated typeshed bug) that had been suppressed by thattype: ignore
, but stopped being when we line-wrapped the assignment.We're using mypy 0.501.
The text was updated successfully, but these errors were encountered: