Skip to content

Use the paired error's code for union operand notes - #22317

Open
xixi-box wants to merge 2 commits into
python:masterfrom
xixi-box:fix/22230-union-operand-note-code
Open

xixi-box wants to merge 2 commits into
python:masterfrom
xixi-box:fix/22230-union-operand-note-code

Conversation

@xixi-box

Copy link
Copy Markdown

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 tagged codes.OPERATOR. A # type: ignore[arg-type] silenced the error and left the notes behind, and mypy then reported:

Error code "operator" not covered by "type: ignore[arg-type]" comment

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 the Unsupported operand types ... [operator] path — behaves exactly as before.

Verification:

  • new check-errorcodes.test case fails before the change (notes keep [operator]) and passes after
  • check-errorcodes.test suite: 135 passed
  • pytest mypy/test/testcheck.py -n8: 8352 passed, 16 skipped, 7 xfailed
  • mypy --config-file mypy_self_check.ini -p mypy: no issues in 196 files

Closes #22230

xixi-box and others added 2 commits October 29, 2026 10:01
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
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spurious note despite suppressing error

1 participant