@@ -127,9 +127,6 @@ def infer_constraints_for_callable(
127127 param_spec_arg_names = []
128128 param_spec_arg_kinds = []
129129
130- own_vars = {t .id for t in callee .variables }
131- type_state .constraints_targets .append (own_vars )
132-
133130 incomplete_star_mapping = False
134131 for i , actuals in enumerate (formal_to_actual ): # TODO: isn't this `enumerate(arg_types)`?
135132 for actual in actuals :
@@ -276,7 +273,6 @@ def infer_constraints_for_callable(
276273 if any (isinstance (v , ParamSpecType ) for v in callee .variables ):
277274 # As a perf optimization filter imprecise constraints only when we can have them.
278275 constraints = filter_imprecise_kinds (constraints )
279- type_state .constraints_targets .pop ()
280276 return constraints
281277
282278
@@ -559,8 +555,8 @@ def any_constraints(options: list[list[Constraint] | None], *, eager: bool) -> l
559555 if filtered_options != options :
560556 return any_constraints (filtered_options , eager = eager )
561557
562- # Try harder: if that didn't work, try to strip typevars not owned by current function .
563- filtered_options = [filter_own (o ) for o in options ]
558+ # Try harder: if that didn't work, try to strip typevars that aren't meta vars .
559+ filtered_options = [exclude_non_meta_vars (o ) for o in options ]
564560 if filtered_options != options :
565561 return any_constraints (filtered_options , eager = eager )
566562
@@ -593,14 +589,13 @@ def filter_satisfiable(option: list[Constraint] | None) -> list[Constraint] | No
593589 return satisfiable
594590
595591
596- def filter_own (option : list [Constraint ] | None ) -> list [Constraint ] | None :
597- """Keep only constraints that reference type vars local to current function, if any."""
598-
599- if not option or not type_state .constraints_targets :
592+ def exclude_non_meta_vars (option : list [Constraint ] | None ) -> list [Constraint ] | None :
593+ # If we had an empty list, keep it intact
594+ if not option :
600595 return option
601- own_vars = type_state . constraints_targets [ - 1 ]
602-
603- return [c for c in option if c .type_var in own_vars ] or None
596+ # However, if none of the options actually references meta vars, better remove
597+ # this constraint entirely.
598+ return [c for c in option if c .type_var . is_meta_var () ] or None
604599
605600
606601def is_same_constraints (x : list [Constraint ], y : list [Constraint ]) -> bool :
0 commit comments