Skip to content

Do not report operand notes when the error they explain is ignored - #22281

Closed
Dextheking1 wants to merge 5 commits into
python:masterfrom
Dextheking1:fix/ignored-operator-note
Closed

Dextheking1 wants to merge 5 commits into
python:masterfrom
Dextheking1:fix/ignored-operator-note

Conversation

@Dextheking1

Copy link
Copy Markdown

The "Right operand is of type ..." note for a binary operation was reported with code operator, even when the error it explains had a different code. For the case in the issue, the error is arg-type, so x <= y # type: ignore[arg-type] suppressed the error but the note still showed, plus a bogus Error code "operator" not covered by "type: ignore[arg-type]" comment note. Expected output is none.

Fix: check_op now passes the filtered error as parent_error for the operand union notes, so the note takes the parent error code and is suppressed together with it. add_error_info also no longer generates "not covered" notes for notes, only for errors.

Test: added testIgnoreOperatorNoteWithDifferentErrorCode to check-ignore.test, with --warn-unused-ignores and no expected output. It passes. Also ran the check-classes, check-callable, check-enum, check-isinstance, check-errorcodes and check-flags data-driven subsets, they pass (1327 passed, apart from testErrorCodeTypeIgnoreMisspelled2 which fails the same way on a clean master checkout here).

Fixes #22230

@Dextheking1
Dextheking1 marked this pull request as ready for review October 23, 2026 02:15
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

colour (https://github.com/colour-science/colour)
- colour/utilities/array.py:4405: note: Right operand is of type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"
- colour/utilities/array.py:4751: note: Right operand is of type "Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]"

cvxpy (https://github.com/cvxpy/cvxpy)
- cvxpy/lin_ops/backends/base.py:356: note: Both left and right operands are unions

freqtrade (https://github.com/freqtrade/freqtrade)
- freqtrade/data/converter/orderflow.py:172: note: Both left and right operands are unions
- freqtrade/strategy/strategy_helper.py:105: note: Left operand is of type "str | bytes | date | timedelta | datetime64[Any] | <7 more items>"
- freqtrade/strategy/strategy_helper.py:106: note: Left operand is of type "str | bytes | date | timedelta | datetime64[Any] | <7 more items>"
- freqtrade/data/btanalysis/trade_parallelism.py:151: note: Right operand is of type "int | Any | datetime64[Any] | timedelta64[Any] | float | complex | floating[Any] | complexfloating[Any, Any]"
- freqtrade/data/btanalysis/trade_parallelism.py:151: note: Right operand is of type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"
- freqtrade/data/btanalysis/trade_parallelism.py:156: note: Right operand is of type "int | Any | datetime64[Any] | timedelta64[Any] | float | complex | floating[Any] | complexfloating[Any, Any]"
- freqtrade/data/btanalysis/trade_parallelism.py:156: note: Left operand is of type "str | bytes | date | datetime | timedelta | <7 more items> | complex | integer[Any] | floating[Any] | complexfloating[Any, Any]"
- freqtrade/util/migrations/migrate_wallet_history.py:153: note: Left operand is of type "int | slice[Any, Any, Any] | ndarray[tuple[int], dtype[numpy.bool[builtins.bool]]]"
- freqtrade/optimize/analysis/lookahead.py:83: note: Left operand is of type "int | slice[Any, Any, Any] | ndarray[tuple[int], dtype[numpy.bool[builtins.bool]]]"

jax (https://github.com/google/jax)
- jax/_src/pallas/mosaic/lowering.py:2174: note: Left operand is of type "int | Squeezed"

sphinx (https://github.com/sphinx-doc/sphinx)
- sphinx/testing/util.py:80:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

scipy-stubs (https://github.com/scipy/scipy-stubs)
- tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

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

2 participants