Commit d86d1737 authored by Frank Bessou's avatar Frank Bessou 🍁
Browse files

fix(typing): correctly type `cached` decorator

parent 50e5fe6bd25d
Pipeline #116365 failed with stages
in 1 minute and 23 seconds
......@@ -25,7 +25,7 @@ import sys
from time import process_time, time
from inspect import isgeneratorfunction
from typing import Any, Optional, Callable, Union
from typing import Any, Optional, Callable, overload, TypeVar
from inspect import getfullargspec
......@@ -121,9 +121,22 @@ class _MultiValuesKeyArgCache(_MultiValuesCache):
return _cache[key]
_T = TypeVar("_T", bound=Callable)
@overload
def cached(
callableobj: Optional[Callable] = None, keyarg: Optional[int] = None, **kwargs: Any
) -> Union[Callable, cached_decorator]:
callableobj: None = None, keyarg: Optional[int] = None, **kwargs: Any
) -> Callable[[_T], _T]:
...
@overload
def cached(callableobj: _T = None, keyarg: Optional[int] = None, **kwargs: Any) -> _T:
...
def cached(callableobj=None, keyarg=None, **kwargs):
"""Simple decorator to cache result of method call."""
kwargs["keyarg"] = keyarg
decorator = cached_decorator(**kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment