Skip to content

Commit 160524d

Browse files
committed
Only defer to higher quality constraints if things are unsolvable
1 parent 5b6a5e4 commit 160524d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

mypy/constraints.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,13 @@ def infer_constraints_for_callable(
277277
if any(isinstance(v, ParamSpecType) for v in callee.variables):
278278
# As a perf optimization filter imprecise constraints only when we can have them.
279279
constraints = filter_imprecise_kinds(constraints)
280-
for pconstraint in priority_constraints:
281-
constraints = [c for c in constraints if c.type_var != pconstraint.type_var]
280+
281+
# TODO: consider passing this up the call stack
282+
for tv in {c.origin_type_var for c in priority_constraints}:
283+
from mypy.solve import solve_constraints
284+
285+
if solve_constraints([tv], constraints + priority_constraints)[0][0] is None:
286+
constraints = [c for c in constraints if c.type_var != tv.id]
282287

283288
return constraints + priority_constraints
284289

0 commit comments

Comments
 (0)