@@ -2902,6 +2902,9 @@ def infer_overload_return_type(
29022902 assert self .msg is self .chk .msg
29032903 with self .msg .filter_errors () as w :
29042904 with self .chk .local_type_map as m :
2905+ # Overload selection should not depend on the context.
2906+ # During this step pretend that we do not have any external information.
2907+ self .type_context .append (None )
29052908 ret_type , infer_type = self .check_call (
29062909 callee = typ ,
29072910 args = args ,
@@ -2911,13 +2914,23 @@ def infer_overload_return_type(
29112914 callable_name = callable_name ,
29122915 object_type = object_type ,
29132916 )
2917+ self .type_context .pop ()
29142918 is_match = not w .has_new_errors ()
29152919 if is_match :
29162920 # Return early if possible; otherwise record info, so we can
29172921 # check for ambiguity due to 'Any' below.
29182922 if not args_contain_any :
2919- self .chk .store_types (m )
2920- return ret_type , infer_type
2923+ # Yes, just again
2924+ # FIXME: find a way to avoid doing this
2925+ return self .check_call (
2926+ callee = typ ,
2927+ args = args ,
2928+ arg_kinds = arg_kinds ,
2929+ arg_names = arg_names ,
2930+ context = context ,
2931+ callable_name = callable_name ,
2932+ object_type = object_type ,
2933+ )
29212934 p_infer_type = get_proper_type (infer_type )
29222935 if isinstance (p_infer_type , CallableType ):
29232936 # Prefer inferred types if possible, this will avoid false triggers for
0 commit comments