Skip to content

Commit

Permalink
Fix line number for decorator issues (python#18392)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Dec 31, 2024
1 parent 7b4f862 commit 9bf5169
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9bf5169

Please sign in to comment.