-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
Bug Report
Narrowing via isinstance and two unions does not seem to do a full crossproduct of possibilities. Spotted when reviewing #20743.
To Reproduce
from __future__ import annotations
class A: ...
class B: ...
class C: ...
def f1(x: A | C, t: type[A] | type[B]):
if isinstance(x, t):
reveal_type(x) # N: Revealed type is "__main__.A"
else:
reveal_type(x) # Revealed type is "__main__.A | __main__.C"Expected Behavior
I would expect the revealed types to be a superset of the results if we did a crossproduct. However, note that <subclass of C and B> is missing. (probably the best way to express this would be to have intersections but... yeah...)
Actual Behavior
Positive branch just has A.
Your Environment
Reproduced in mypy-play
- Mypy version used: master
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.12
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder