Closed
Description
Bug Report
When using a decorator on the decorated function within the definition of another decorator, mypy reports false positives.
To Reproduce
from typing import Callable, TypeVar
from typing_extensions import ParamSpec, Concatenate
P = ParamSpec("P")
T = TypeVar("T")
def identity(func: Callable[P, T]) -> Callable[P, T]:
def _wrapped(*args: P.args, **kwargs: P.kwargs) -> T:
return func(*args, **kwargs)
return _wrapped
def int_identity(func: Callable[Concatenate[int, P], T]) -> Callable[Concatenate[int, P], T]:
# identify should preserve the signature of _wrapped
# error: Argument 1 to "identity" has incompatible type "Callable[[Arg(int, 'number'), **P], T]"; expected "Callable[[Arg(int, 'number'), **P], T]"
@identity
def _wrapped(number: int, *args: P.args, **kwargs: P.kwargs) -> T:
return func(number, *args, **kwargs)
return _wrapped
Expected Behavior
The code should pass type-check with no errors.
Actual Behavior
Got error:
error: Argument 1 to "identity" has incompatible type "Callable[[Arg(int, 'number'), **P], T]"; expected "Callable[[Arg(int, 'number'), **P], T]"
Your Environment
- Mypy version used: 0.960
- Mypy command-line flags:
--strict
- Python version used: Python 3.8.10
- Operating system and version: WSL2 - Ubuntu 20.04