Skip to content

Commit 3cafa45

Browse files
committed
Prevent discarding ErasedType - it's better to infer nothing than to infer a union subset
1 parent b5b7981 commit 3cafa45

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mypy/constraints.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,10 +559,16 @@ def any_constraints(options: list[list[Constraint] | None], *, eager: bool) -> l
559559
if filtered_options != options:
560560
return any_constraints(filtered_options, eager=eager)
561561

562-
if eager and all_similar:
562+
if (
563+
eager
564+
and all_similar
565+
and not any(isinstance(c.target, ErasedType) for group in valid_options for c in group)
566+
):
563567
# Now we know all constraints might be satisfiable and have similar structure.
564568
# Solver will apply meets and joins as necessary, return everything we know.
565569
# Just deduplicate to reduce the amount of work.
570+
# If any targets are erased, fall back to empty, otherwise they will be discarded
571+
# by solver, causing false early matches.
566572
all_combined = sum(valid_options, [])
567573
return list(dict.fromkeys(all_combined))
568574

0 commit comments

Comments
 (0)