Skip to content

Commit

Permalink
Fix deferred case
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Jul 5, 2023
1 parent b33386c commit e4d7096
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ def _visit_overloaded_func_def(self, defn: OverloadedFuncDef) -> None:
defn.impl.accept(self)
if defn.info:
found_method_base_classes = self.check_method_override(defn)
if defn.is_explicit_override and not found_method_base_classes:
if (
defn.is_explicit_override
and not found_method_base_classes
and found_method_base_classes is not None
):
self.msg.no_overridable_method(defn.name, defn)
elif (
found_method_base_classes
Expand Down Expand Up @@ -4760,7 +4764,11 @@ def visit_decorator(self, e: Decorator) -> None:
# For overloaded functions we already checked override for overload as a whole.
if e.func.info and not e.func.is_dynamic() and not e.is_overload:
found_method_base_classes = self.check_method_override(e)
if e.func.is_explicit_override and not found_method_base_classes:
if (
e.func.is_explicit_override
and not found_method_base_classes
and found_method_base_classes is not None
):
self.msg.no_overridable_method(e.func.name, e.func)
elif (
found_method_base_classes
Expand Down
26 changes: 26 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,32 @@ class C(A):
def f(self, y: int | str) -> str: pass
[typing fixtures/typing-override.pyi]

[case explicitOverrideCyclicDependency]
# flags: --python-version 3.12
import b
[file a.py]
from typing import override
import b
import c

class A(b.B):
@override # This is fine
@c.deco
def meth(self) -> int: ...
[file b.py]
import a
import c

class B:
@c.deco
def meth(self) -> int: ...
[file c.py]
from typing import TypeVar, Tuple, Callable
T = TypeVar('T')
def deco(f: Callable[..., T]) -> Callable[..., Tuple[T, int]]: ...
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-override.pyi]

[case requireExplicitOverrideMethod]
# flags: --strict-override-decorator --python-version 3.12
from typing import override
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/fixtures/typing-override.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Optional = 0
Self = 0
Tuple = 0
ClassVar = 0
Callable = 0

T = TypeVar('T')
T_co = TypeVar('T_co', covariant=True)
Expand Down

0 comments on commit e4d7096

Please sign in to comment.