Skip to content

Reprocess decorators instead of the function they decorate #4989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,11 @@ def _visit_func_def(self, defn: FuncDef) -> None:
"""Type check a function definition."""
self.check_func_item(defn, name=defn.name())
if defn.info:
if not defn.is_dynamic() and not defn.is_overload:
# If the definition is the implementation for an overload, the legality
# of the override has already been typechecked.
if not defn.is_dynamic() and not defn.is_overload and not defn.is_decorated:
# If the definition is the implementation for an
# overload, the legality of the override has already
# been typechecked, and decorated methods will be
# checked when the decorator is.
self.check_method_override(defn)
self.check_inplace_operator_method(defn)
if defn.original_def:
Expand Down
30 changes: 30 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,36 @@ a.py:3: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports"
==
==

[case testDecoratorMethodCompat]
from typing import Callable, List, TypeVar
import x

class Base: pass
_Base = TypeVar('_Base', bound=Base)

def dec(f: Callable[[_Base], int]) -> Callable[[_Base], List[int]]: pass

class B(Base):
def foo(self) -> List[int]: pass

class A(B):
@dec
def foo(self) -> int:
x.lol()
return 12

[file x.py]
def lol() -> str: pass
[file x.py.2]
def lol() -> int: pass
[file x.py.3]
def lol() -> str: pass

[builtins fixtures/list.pyi]
[out]
==
==

[case testPreviousErrorInDecoratedFunction]
import a
[file a.py]
Expand Down