Repository navigation
Conversation
When a binary operator fails with [arg-type] because an operand is a union,
mypy emits two explanatory notes ("Left/Right operand is of type ..."), but they
were always tagged with codes.OPERATOR. A `# type: ignore[arg-type]` therefore
silenced the error and left the notes behind, and mypy then reported
`Error code "operator" not covered by "type: ignore[arg-type]" comment` - noise
naming a code the user never saw.
Pass the paired error's code down to those notes. The default stays
codes.OPERATOR, so every other call site behaves exactly as before.
Closes python#22230
for more information, see https://pre-commit.ci
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a binary operator fails with
[arg-type]because an operand is a union, mypy emits explanatory notes ("Left/Right operand is of type ..."), but they were always taggedcodes.OPERATOR. A# type: ignore[arg-type]silenced the error and left the notes behind, and mypy then reported:which names a code the user never had a chance to see.
This passes the paired error's own code down to those notes. The default remains
codes.OPERATOR, so every other call site — including theUnsupported operand types ... [operator]path — behaves exactly as before.Verification:
check-errorcodes.testcase fails before the change (notes keep[operator]) and passes aftercheck-errorcodes.testsuite: 135 passedpytest mypy/test/testcheck.py -n8: 8352 passed, 16 skipped, 7 xfailedmypy --config-file mypy_self_check.ini -p mypy: no issues in 196 filesCloses #22230