Skip to content

Associate union notes with their parent error - #22232

Open
zhengguangzhuo wants to merge 1 commit into
python:masterfrom
zhengguangzhuo:zhengguangzhuo/mypy-suppress-related-note-22230
Open

zhengguangzhuo wants to merge 1 commit into
python:masterfrom
zhengguangzhuo:zhengguangzhuo/mypy-suppress-related-note-22230

Conversation

@zhengguangzhuo

Copy link
Copy Markdown

Fixes #22230.

The union-operand explanatory note is currently tagged with operator even when it accompanies a different parent error such as arg-type. As a result, type: ignore[arg-type] suppresses the error but leaves the note and a spurious error-code mismatch note.

Pass the originating error to the note helpers so the note inherits the parent diagnostic's error code and is suppressed together. Add a regression test using the issue reproducer.

Validation:

  • uv run --no-project --with-requirements dev-requirements.txt -- python runtests.py check-errorcodes.test check-classes.test self passed (135 + 613 tests; 1 expected failure; self-check passed for 347 files).
  • Ruff and Black checks for the changed files passed; git diff --check passed.
  • Full project lint could not start because installing the pinned ShellCheck hook was blocked by network access to sum.golang.org.

Prepared with assistance from OpenAI Codex; the submitting account holder is responsible for reviewing it.

@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]"

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:2175: note: Left operand is of type "int | Squeezed"

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