From 9bf5169ae401bd07d10f02976167f609ea14d8da Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Tue, 31 Dec 2024 15:09:26 -0800 Subject: [PATCH] Fix line number for decorator issues (#18392) Fixes #18391 --- mypy/checker.py | 2 +- test-data/unit/check-functions.test | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 2b078f721736..3d0f40283606 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -5117,7 +5117,7 @@ def visit_decorator_inner(self, e: Decorator, allow_empty: bool = False) -> None self.fail(message_registry.MULTIPLE_OVERLOADS_REQUIRED, e) continue dec = self.expr_checker.accept(d) - temp = self.temp_node(sig, context=e) + temp = self.temp_node(sig, context=d) fullname = None if isinstance(d, RefExpr): fullname = d.fullname or None diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index e4b8c31e8b46..18425efb9cb0 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -916,10 +916,19 @@ f(None) # E: Too many arguments for "f" from typing import Any, Callable def dec1(f: Callable[[Any], None]) -> Callable[[], None]: pass def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass -@dec1 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]" -@dec2 +@dec1 +@dec2 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]" def f(x): pass +def faulty(c: Callable[[int], None]) -> Callable[[tuple[int, int]], None]: + return lambda x: None + +@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[Tuple[int, int]], None]"; expected "Callable[[int], None]" +@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[str], None]"; expected "Callable[[int], None]" +def g(x: str) -> None: + return None +[builtins fixtures/tuple.pyi] + [case testInvalidDecorator2] from typing import Any, Callable def dec1(f: Callable[[Any, Any], None]) -> Callable[[], None]: pass