Skip to content

Conversation

sterliakov
Copy link
Collaborator

Fixes #19492.

In #19695 I tried to add another set of heuristics to any_constraints, but can't get that working: trying to join/meet all similar constraints together breaks inference in other cases, and only doing that for Any would be somewhat non-trivial. This PR reverts behaviour introduced in #19492 when LHS of the expression contains Any. Outer context is still included in all other cases, and this seems to strike a good balance.

Copy link
Contributor

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

discord.py (https://github.com/Rapptz/discord.py)
+ discord/activity.py:416: error: Incompatible types in assignment (expression has type "Any | dict[Any, Any]", variable has type "ActivityAssets")  [assignment]

@sterliakov sterliakov requested a review from ilevkivskyi August 28, 2025 11:14
Copy link
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.

Any-related logic w.r.t. inference is already quite ad-hoc, so TBH this doesn't make it much worse.

@ilevkivskyi ilevkivskyi merged commit e633140 into python:master Aug 28, 2025
20 checks passed
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.

Regression: dict | None or dict fallback breaks type inference for nested dicts after PR #19249

2 participants