@@ -89,10 +89,13 @@ def __init__(self, node, ctx):
8989 self ._node = node
9090 self ._protocol_cache = set ()
9191 self ._recursive_annots_cache = set ()
92+ self ._error_subst = None
93+ self ._reset_errors ()
94+
95+ def _reset_errors (self ):
9296 self ._protocol_error = None
9397 self ._noniterable_str_error = None
9498 self ._typed_dict_error = None
95- self ._error_subst = None
9699
97100 @contextlib .contextmanager
98101 def _track_partially_matched_protocols (self ):
@@ -143,11 +146,10 @@ def compute_subst(self, formal_args, arg_dict, view, alias_map=None):
143146 subst = datatypes .AliasingDict ()
144147 if alias_map :
145148 subst .uf = alias_map
146- self ._protocol_error = None
147- self ._noniterable_str_error = None
148149 self ._error_subst = None
149150 self_subst = None
150151 for name , formal in formal_args :
152+ self ._reset_errors ()
151153 actual = arg_dict [name ]
152154 subst = self ._match_value_against_type (actual , formal , subst , view )
153155 if subst is None :
@@ -195,8 +197,6 @@ def bad_matches(self, var, other_type):
195197 view = views .send (skip_future )
196198 except StopIteration :
197199 break
198- self ._protocol_error = None
199- self ._noniterable_str_error = None
200200 if self .match_var_against_type (var , other_type , {}, view ) is None :
201201 if self ._node .HasCombination (list (view .values ())):
202202 bad .append ((view , self ._error_details ()))
@@ -250,6 +250,7 @@ def match_from_mro(self, left, other_type, allow_compat_builtins=True):
250250
251251 def match_var_against_type (self , var , other_type , subst , view ):
252252 """Match a variable against a type."""
253+ self ._reset_errors ()
253254 if var .bindings :
254255 return self ._match_value_against_type (view [var ], other_type , subst , view )
255256 else : # Empty set of values. The "nothing" type.
@@ -985,7 +986,6 @@ def _match_callable_instance(self, left, instance, other_type, subst, view):
985986
986987 def _match_dict_against_typed_dict (self , left , other_type ):
987988 assert isinstance (other_type , typed_dict .TypedDictClass )
988- self ._typed_dict_error = None
989989 if not isinstance (left , abstract .Dict ):
990990 return False
991991 missing , extra = other_type .props .check_keys (left .pyval .keys ())
0 commit comments