Allow type checkers to ignore specific error codes#2153
Allow type checkers to ignore specific error codes#2153davidhalter wants to merge 9 commits intopython:mainfrom
Conversation
57549ff to
8d74622
Compare
|
This will need changes in the spec text as well as the conformance suite, and it will need to be approved by the Typing Council. (Personally, I'm supportive of doing something like this, but haven't thought too much about the exact proposal yet.) |
|
@JelleZijlstra What do you have in mind? My problem is that the spec is currently not specific about this at all (see this discussion) and I haven't gotten much feedback on where people would want to take this in the same thread. Would you want to add something to the spec like this:
This is of course just my initial idea, any guidance is appreciated. The current spec doesn't really talk about this, so this should be more of an addition. |
|
Something like that, yes. If the spec doesn't currently discuss this, that means we should add it. The spec text shouldn't call out any specific type checker (like mypy). Instead, we should generically say that type checkers may use syntax like |
8d74622 to
f4a919a
Compare
|
I have pushed a new update to the spec. It's just a small addition and I hope it reflects the general sentiment of the discussion in the typing discuss. As always I'm happy to integrate feedback. |
|
@JelleZijlstra Would you mind looking at this spec change? I'd prefer at least a single opinion before I bring this to the typing council. |
|
I removed the parts where I tried to specify how whitespace after |
|
|
||
| # The following type violation should be suppressed. | ||
| z: int = "" # type: ignore[additional_stuff] | ||
| z: int = "" # type: ignore[assignment] |
There was a problem hiding this comment.
| z: int = "" # type: ignore[assignment] | |
| z: int = "" # type: ignore[assignment] # E? |
There was a problem hiding this comment.
tbh I think it would be more "fair" to not change this line to use the type code that matches mypy/zuban. There's no specified requirement that all type checkers must use the type code assignment for this situation. So I think all type checkers that do strict handling of ignores with error codes should equally rely on # E? on this line.
There was a problem hiding this comment.
This is definitely fair. I'm indifferent here and will wait if there are any other opinions here.
There was a problem hiding this comment.
I obviously don't have a vote here, but I agree with @carljm :)
ty has the same behaviour as zuban and mypy here but has different error codes. I would expect this change to result in ty being marked fully conformant with this file, just like mypy and zuban, but it is not because you're using a mypy/zuban-specific error code
There was a problem hiding this comment.
Yes, I think it might be best to actually use a completely made up error code.
# type: ignore[an-empty-str-is-not-an-int], for the type checkers with really specific error codes.
There was a problem hiding this comment.
Oh nice, I didn't even realize that Ty was also affected by this. It feels like the change makes even more sense then. I changed it towards the random error code Jelle proposed.
There was a problem hiding this comment.
yes, we changed our behaviour recently because we came to the conclusion that mypy's/zuban's behaviour was much more user-friendly for folks trying to run multiple type checkers on their codebase (not unusual for library authors)
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Carl Meyer <carl@oddbird.net>
| # type: ignore # <comment or other marker> | ||
|
|
||
| The form ``# type: ignore[...]`` may be used to suppress only type errors with a | ||
| given error code, though support for this is optional and may vary by type checker: |
There was a problem hiding this comment.
What about also documenting that multiple error codes can be given (comma-separated), and unrecognized error codes should be ignored, if a type checker supports ignoring errors based on specific error code, as @ilevkivskyi suggested here.
There was a problem hiding this comment.
Are there any other opinions on this? I'm pretty open to changes here.
I personally think that the comma separated form doesn't need to be specified explicitly.
unrecognized error codes should be ignored, if a type checker supports ignoring errors based on specific error code
Does this mean that Mypy would need to ignore the error code "undefined"? Currently it adds errors at least when using --warn-unused-ignores: https://mypy-play.net/?mypy=latest&python=3.12&flags=warn-unused-ignores&gist=27ebc9511f193a9f348b0235412cbcc9
Changes the error code from
additional_stufftoassignment(as Mypy uses it).This was the proposal Rebecca: