From d4268e048a970d4287be288865aa355df258ddf1 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 29 Nov 2021 13:10:20 +0300 Subject: [PATCH 1/3] Addresses review of #11630 --- mypy/checker.py | 12 +++++++++++- test-data/unit/check-overloading.test | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/mypy/checker.py b/mypy/checker.py index 6505100cec6f..8f8e7316a3d4 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -512,7 +512,17 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None: impl_type = inner_type elif isinstance(inner_type, Instance): inner_call = get_proper_type( - find_member('__call__', inner_type, inner_type, is_operator=True) + analyze_member_access( + name='__call__', + typ=inner_type, + context=defn.impl, + is_lvalue=False, + is_super=False, + is_operator=False, + msg=self.msg, + original_type=inner_type, + chk=self, + ), ) if isinstance(inner_call, CallableType): impl_type = inner_call diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 8aa29f650270..35299caf56cb 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -5382,6 +5382,20 @@ def f_c(arg: int) -> None: ... def f_c(arg: str) -> None: ... @dec_c # E: Overloaded function implementation does not accept all possible arguments of signature 2 def f_c(arg): ... + +class D: + def __getattr__(self, attr: str) -> Callable[[Union[int, str]], None]: + ... # Will return `__call__` in runtime + +def dec_d(f: Callable[..., Any]) -> D: + return D() + +@overload +def f_d(__arg: int) -> None: ... +@overload +def f_d(__arg: str) -> None: ... +@dec_d +def f_d(__arg: Union[int, str]) -> None: ... [builtins fixtures/dict.pyi] [case testOverloadWithErrorDecorator] From 9866fd0991696822b77b7f619e8578ae8a376d19 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 29 Nov 2021 15:09:40 +0300 Subject: [PATCH 2/3] Addresses review of #11630 --- mypy/checker.py | 2 +- test-data/unit/check-overloading.test | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 8f8e7316a3d4..ac4b905643ea 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -518,7 +518,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None: context=defn.impl, is_lvalue=False, is_super=False, - is_operator=False, + is_operator=True, msg=self.msg, original_type=inner_type, chk=self, diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index 35299caf56cb..81caae49c24b 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -5385,7 +5385,7 @@ def f_c(arg): ... class D: def __getattr__(self, attr: str) -> Callable[[Union[int, str]], None]: - ... # Will return `__call__` in runtime + ... # __getattr__ is not called for implicit `__call__` def dec_d(f: Callable[..., Any]) -> D: return D() @@ -5394,7 +5394,7 @@ def dec_d(f: Callable[..., Any]) -> D: def f_d(__arg: int) -> None: ... @overload def f_d(__arg: str) -> None: ... -@dec_d +@dec_d # E: "D" not callable def f_d(__arg: Union[int, str]) -> None: ... [builtins fixtures/dict.pyi] From 394b37768ab9e3483b899cb44702ce66e7a5250f Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Tue, 30 Nov 2021 20:46:03 -0800 Subject: [PATCH 3/3] remove duplicate test case from #11637 --- test-data/unit/check-overloading.test | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/test-data/unit/check-overloading.test b/test-data/unit/check-overloading.test index a57c29b358f2..0a69b46e7641 100644 --- a/test-data/unit/check-overloading.test +++ b/test-data/unit/check-overloading.test @@ -5382,20 +5382,6 @@ def f_c(arg: int) -> None: ... def f_c(arg: str) -> None: ... @dec_c # E: Overloaded function implementation does not accept all possible arguments of signature 2 def f_c(arg): ... - -class D: - def __getattr__(self, attr: str) -> Callable[[Union[int, str]], None]: - ... # __getattr__ is not called for implicit `__call__` - -def dec_d(f: Callable[..., Any]) -> D: - return D() - -@overload -def f_d(__arg: int) -> None: ... -@overload -def f_d(__arg: str) -> None: ... -@dec_d # E: "D" not callable -def f_d(__arg: Union[int, str]) -> None: ... [builtins fixtures/dict.pyi] [case testOverloadWithErrorDecorator] @@ -5423,6 +5409,7 @@ def f_e(arg): ... class Bad2: def __getattr__(self, attr): + # __getattr__ is not called for implicit `__call__` if attr == "__call__": return lambda *a, **kw: print(a, kw) raise AttributeError