Skip to content

Correctly aggregate narrowing information on parent expressions#21206

Merged
hauntsaninja merged 4 commits intopython:masterfrom
hauntsaninja:parentfix
Apr 13, 2026
Merged

Correctly aggregate narrowing information on parent expressions#21206
hauntsaninja merged 4 commits intopython:masterfrom
hauntsaninja:parentfix

Conversation

@hauntsaninja
Copy link
Copy Markdown
Collaborator

@hauntsaninja hauntsaninja commented Apr 12, 2026

Fixes #21204 , fixes #20596

The extra narrowing we perform in mypy 1.20 exposes this much longer standing issue

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This makes things much cleaner.

@github-actions
Copy link
Copy Markdown
Contributor

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

spark (https://github.com/apache/spark)
- python/pyspark/pandas/typedef/typehints.py:163: error: Item "str" of "str | type | dtype[Any] | ExtensionDtype" has no attribute "__args__"  [union-attr]
- python/pyspark/pandas/typedef/typehints.py:163: error: Item "type" of "str | type | dtype[Any] | ExtensionDtype" has no attribute "__args__"  [union-attr]
- python/pyspark/pandas/typedef/typehints.py:163: error: Item "dtype[Any]" of "str | type | dtype[Any] | ExtensionDtype" has no attribute "__args__"  [union-attr]
- python/pyspark/pandas/typedef/typehints.py:163: error: Item "ExtensionDtype" of "str | type | dtype[Any] | ExtensionDtype" has no attribute "__args__"  [union-attr]

altair (https://github.com/vega/altair)
- altair/vegalite/v6/api.py:5171: error: Item "UndefinedType" of "Any | Sequence[VariableParameter | TopLevelSelectionParameter | SelectionParameter] | UndefinedType" has no attribute "__iter__" (not iterable)  [union-attr]

discord.py (https://github.com/Rapptz/discord.py)
- discord/channel.py:2192: error: Incompatible return value type (got "list[VoiceChannel | StageChannel | ForumChannel | TextChannel | CategoryChannel]", expected "list[TextChannel]")  [return-value]
- discord/channel.py:2199: error: Incompatible return value type (got "list[VoiceChannel | StageChannel | ForumChannel | TextChannel | CategoryChannel]", expected "list[VoiceChannel]")  [return-value]
- discord/channel.py:2209: error: Incompatible return value type (got "list[VoiceChannel | StageChannel | ForumChannel | TextChannel | CategoryChannel]", expected "list[StageChannel]")  [return-value]
- discord/channel.py:2219: error: Incompatible return value type (got "list[VoiceChannel | StageChannel | ForumChannel | TextChannel | CategoryChannel]", expected "list[ForumChannel]")  [return-value]

jax (https://github.com/google/jax)
+ jax/_src/interpreters/pxla.py:570: error: Unused "type: ignore" comment  [unused-ignore]

@hauntsaninja hauntsaninja merged commit ff31bb2 into python:master Apr 13, 2026
24 checks passed
@hauntsaninja hauntsaninja deleted the parentfix branch April 13, 2026 18:35
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.

[1.20 regression] narrowing failure with unrelated boolean Regression with narrowing with multiple hasattr

2 participants