Skip to content

Commit 674b25f

Browse files
committed
Before you murder me, a constraint T <: (A | B) where T: (A | C) can be satisfied by T = A
1 parent 99f7bf4 commit 674b25f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mypy/constraints.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,21 +571,21 @@ def any_constraints(options: list[list[Constraint] | None], *, eager: bool) -> l
571571
def filter_satisfiable(option: list[Constraint] | None) -> list[Constraint] | None:
572572
"""Keep only constraints that can possibly be satisfied.
573573
574-
Currently, we filter out constraints where target is not a subtype of the upper bound.
574+
Currently, we filter out constraints where target does not overlap with the upper bound.
575575
Since those can be never satisfied. We may add more cases in future if it improves type
576576
inference.
577577
"""
578+
from mypy.meet import is_overlapping_types
579+
578580
if not option:
579581
return option
580582

581583
satisfiable = []
582584
for c in option:
583585
if isinstance(c.origin_type_var, TypeVarType) and c.origin_type_var.values:
584-
if any(
585-
mypy.subtypes.is_subtype(c.target, value) for value in c.origin_type_var.values
586-
):
586+
if any(is_overlapping_types(c.target, value) for value in c.origin_type_var.values):
587587
satisfiable.append(c)
588-
elif mypy.subtypes.is_subtype(c.target, c.origin_type_var.upper_bound):
588+
elif is_overlapping_types(c.target, c.origin_type_var.upper_bound):
589589
satisfiable.append(c)
590590
if not satisfiable:
591591
return None

0 commit comments

Comments
 (0)