You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression: dict | None or dict fallback breaks type inference for nested dicts after PR #19249 #19492
After upgrading mypy past PR #19249, we observed new errors related to dictionary fallback using or expressions when value types are unions of nested dicts and optional types.
This appears to be a regression in type inference, as the same code passed in previous versions of mypy.
This only used to work because of Any, {'x': s} was inferred as dict[str, Any] to match the LHS (so not an inference regression, strictly speaking, but still somewhat annoying).
OK, the context is applied correctly. The problem is that we're failing to apply our "ignore trivial (only Any) constraints when or-ing them" fallback when constraints for multiple targets coexist.
Activity
sterliakov commentedon Jul 26, 2025
Thanks for bisecting!
This only used to work because of
Any,{'x': s}was inferred asdict[str, Any]to match the LHS (so not an inference regression, strictly speaking, but still somewhat annoying).sterliakov commentedon Jul 26, 2025
OK, the context is applied correctly. The problem is that we're failing to apply our "ignore trivial (only
Any) constraints when or-ing them" fallback when constraints for multiple targets coexist.We're trying to
orthe following constraints:Noneis ignored. We canorsubsets of those constraints for every variable, but can'torwhole groups.mypy/mypy/constraints.py
Lines 539 to 544 in d528707
I'll try to tackle that TODO sooner or later (it should be enough to resolve this ticket), but feel free to help:)
JukkaL commentedon Aug 19, 2025
@ilevkivskyi Would you have time to have a look at this, since this is potentially blocking the next release?
ilevkivskyi commentedon Aug 19, 2025
I can't give any promises, but I will try to look at this in the next few days.
sterliakov commentedon Aug 20, 2025
Okay, let's see the primer first, but it looks like I was overcomplicating things again.
ilevkivskyi commentedon Aug 21, 2025
@sterliakov Is my help still needed here, or you are working on this? (I see there are some problems in the PR for type variables with values.)
sterliakov commentedon Aug 22, 2025
@ilevkivskyi I'm looking into them, yes:)
Do not use outer context for `or` expr inference if the LHS has Any (p…