Skip to content

Commit 6ff817f

Browse files
committed
Experiment: literally just ignore the context altogether?
1 parent 917d781 commit 6ff817f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

mypy/checkexpr.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test-data/unit/check-overloading.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6865,5 +6865,5 @@ def gather(*fns: object) -> int: ...
68656865

68666866
def crash() -> None:
68676867
foo: str
6868-
(foo,) = gather(0)
6868+
(foo,) = gather(0) # E: Incompatible types in assignment (expression has type "int", variable has type "str")
68696869
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)