From 0bb2d1680e8b9522108b38d203cb73021a617e64 Mon Sep 17 00:00:00 2001 From: Naomi Seyfer Date: Wed, 22 Feb 2017 05:24:37 -0800 Subject: [PATCH] Don't check method subtyping when supertype method's type is `Any` (#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. --- mypy/checker.py | 2 ++ test-data/unit/check-functions.test | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/mypy/checker.py b/mypy/checker.py index b343e644d590..1684278ca319 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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) diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 5fb89326ce8a..2996213c8209 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -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