Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
logilab-common
Commits
3f8060ce3d06
Commit
d86d1737
authored
Dec 13, 2021
by
Frank Bessou
🍁
Browse files
fix(typing): correctly type `cached` decorator
parent
50e5fe6bd25d
Pipeline
#116365
failed with stages
in 1 minute and 23 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
logilab/common/decorators.py
View file @
3f8060ce
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment