Skip to content

Commit

Permalink
Don't check method subtyping when supertype method's type is Any (#…
Browse files Browse the repository at this point in the history
…2880)

Previously, we were bailing out with an error because we thought that overriding
a non-method type with a method type was bad.

This comes up when you have an untyped decorator on a supertype method.

Fixes #2782.
  • Loading branch information
sixolet authored and JukkaL committed Feb 22, 2017
1 parent 641d953 commit 0bb2d16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ def check_method_override_for_base_with_name(
name,
base.name(),
defn)
elif isinstance(original_type, AnyType):
pass
else:
self.msg.signature_incompatible_with_supertype(
defn.name(), name, base.name(), defn)
Expand Down
19 changes: 19 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ ee_def = specific_1 # E: Incompatible types in assignment (expression has type C

[builtins fixtures/dict.pyi]

[case testSubtypingFunctionsDecorated]
from typing import Any

# untyped decorator
def deco(f): pass

class A:
@deco
def f(self) -> Any:
pass

class B(A):
@deco
def f(self) -> Any:
pass

[builtins fixtures/list.pyi]


[case testLackOfNames]
def f(__a: int, __b: str) -> None: pass
def g(a: int, b: str) -> None: pass
Expand Down

0 comments on commit 0bb2d16

Please sign in to comment.