Skip to content

Use union of current context and left side for right side narrowing of binary ops #19249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sterliakov
Copy link
Collaborator

@sterliakov sterliakov commented Jun 7, 2025

Fixes #12001. Fixes #6898. Fixes #15368. Improves #17790 and #11508.

When encountering a {and,or} b, we used to use a as primary context for b inference. This results in weird errors when a and b are completely unrelated, and in many cases return type/assignment type context can do much better. Inferring to union should be harmless in most cases, so use union of a and current context instead.

@sterliakov sterliakov changed the title Use union of current context and left side for right side narrowing Use union of current context and left side for right side narrowing of binary ops Jun 7, 2025

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 7, 2025

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:384: error: Incompatible types in assignment (expression has type "Any | dict[Any, Any]", variable has type "ActivityAssets")  [assignment]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant