diff --git a/pyproject.toml b/pyproject.toml index f528a0a..0c33318 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ theine-core = "^0.4.3" pytest = "^7.2.1" pytest-benchmark = "^4.0.0" typing-extensions = "^4.4.0" -mypy = "^1.0.0" +mypy = "1.11.1" django = "^3.2" pytest-django = "^4.5.2" pytest-asyncio = "^0.20.3" diff --git a/theine/theine.py b/theine/theine.py index 70faa5f..bb20923 100644 --- a/theine/theine.py +++ b/theine/theine.py @@ -13,18 +13,25 @@ Hashable, List, Optional, - Tuple, + TYPE_CHECKING, Tuple, Type, TypeVar, Union, cast, ) +from mypy_extensions import KwArg, VarArg from theine_core import ClockProCore, LruCore, TlfuCore from typing_extensions import ParamSpec, Protocol from theine.exceptions import InvalidTTL from theine.models import CacheStats +P = ParamSpec("P") +R = TypeVar("R", covariant=True, bound=Any) +R_A = TypeVar("R_A", covariant=True, bound=Union[Awaitable[Any], Callable[..., Any]]) +if TYPE_CHECKING: + from functools import _Wrapped + sentinel = object() @@ -105,10 +112,6 @@ def len(self) -> int: "clockpro": ClockProCore, } -P = ParamSpec("P") -R = TypeVar("R", covariant=True, bound=Any) -R_A = TypeVar("R_A", covariant=True, bound=Union[Awaitable[Any], Callable[..., Any]]) - @dataclass class EventData: @@ -244,7 +247,7 @@ def __init__( self.typed = typed self.lock = lock - def __call__(self, fn: Callable[P, R_A]) -> Cached[P, R_A]: + def __call__(self, fn: Callable[P, R_A]) -> '_Wrapped[P, R_A, [VarArg(Any), KwArg(Any)], R_A]': wrapper = Wrapper(fn, self.timeout, self.cache, self.typed, self.lock) return update_wrapper(wrapper, fn)