Skip to content

Commit

Permalink
Issue an error when overriding typeguard with non-typeguard in subcla…
Browse files Browse the repository at this point in the history
…ss (#10300)

Closes #9928.

Issue an error about incompatible signature when trying to override typeguard method 
with non-typeguard one.
  • Loading branch information
kamilturek authored Apr 12, 2021
1 parent f463a39 commit 49cd412
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,9 @@ def check_override(self, override: FunctionLike, original: FunctionLike,
if isinstance(original, FunctionLike) and isinstance(override, FunctionLike):
if original_class_or_static and not override_class_or_static:
fail = True
elif isinstance(original, CallableType) and isinstance(override, CallableType):
if original.type_guard is not None and override.type_guard is None:
fail = True

if is_private(name):
fail = False
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-typeguard.test
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ def main(a: object) -> None:
reveal_type(a) # N: Revealed type is "builtins.float"
[builtins fixtures/tuple.pyi]

[case testTypeGuardMethodOverride-skip]
[case testTypeGuardMethodOverride]
from typing_extensions import TypeGuard
class C:
def is_float(self, a: object) -> TypeGuard[float]: pass
class D(C):
def is_float(self, a: object) -> bool: pass # E: Some error
def is_float(self, a: object) -> bool: pass # E: Signature of "is_float" incompatible with supertype "C"
[builtins fixtures/tuple.pyi]

0 comments on commit 49cd412

Please sign in to comment.