Skip to content

Commit 9bf5169

Browse files
authoredDec 31, 2024··
Fix line number for decorator issues (#18392)
Fixes #18391
1 parent 7b4f862 commit 9bf5169

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎mypy/checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5117,7 +5117,7 @@ def visit_decorator_inner(self, e: Decorator, allow_empty: bool = False) -> None
51175117
self.fail(message_registry.MULTIPLE_OVERLOADS_REQUIRED, e)
51185118
continue
51195119
dec = self.expr_checker.accept(d)
5120-
temp = self.temp_node(sig, context=e)
5120+
temp = self.temp_node(sig, context=d)
51215121
fullname = None
51225122
if isinstance(d, RefExpr):
51235123
fullname = d.fullname or None

‎test-data/unit/check-functions.test

+11-2
Original file line numberDiff line numberDiff line change
@@ -916,10 +916,19 @@ f(None) # E: Too many arguments for "f"
916916
from typing import Any, Callable
917917
def dec1(f: Callable[[Any], None]) -> Callable[[], None]: pass
918918
def dec2(f: Callable[[Any, Any], None]) -> Callable[[Any], None]: pass
919-
@dec1 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]"
920-
@dec2
919+
@dec1
920+
@dec2 # E: Argument 1 to "dec2" has incompatible type "Callable[[Any], Any]"; expected "Callable[[Any, Any], None]"
921921
def f(x): pass
922922

923+
def faulty(c: Callable[[int], None]) -> Callable[[tuple[int, int]], None]:
924+
return lambda x: None
925+
926+
@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[Tuple[int, int]], None]"; expected "Callable[[int], None]"
927+
@faulty # E: Argument 1 to "faulty" has incompatible type "Callable[[str], None]"; expected "Callable[[int], None]"
928+
def g(x: str) -> None:
929+
return None
930+
[builtins fixtures/tuple.pyi]
931+
923932
[case testInvalidDecorator2]
924933
from typing import Any, Callable
925934
def dec1(f: Callable[[Any, Any], None]) -> Callable[[], None]: pass

0 commit comments

Comments
 (0)
Please sign in to comment.