Skip to content

Commit 193dd62

Browse files
committed
Fix #393: Improve ambiguous overloads for decorators.
1 parent 1ea3422 commit 193dd62

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

src/cachetools/__init__.pyi

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,25 @@ def cached(
168168
key: Callable[..., _KT] = ...,
169169
lock: AbstractContextManager[Any] | None = None,
170170
condition: _AbstractCondition | None = None,
171-
info: Literal[True] = ...,
172-
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
171+
info: Literal[False] = ...,
172+
) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ...
173173
@overload
174174
def cached(
175175
cache: MutableMapping[_KT, Any] | None,
176176
key: Callable[..., _KT] = ...,
177177
lock: AbstractContextManager[Any] | None = None,
178178
condition: _AbstractCondition | None = None,
179-
info: Literal[False] = ...,
180-
) -> Callable[[Callable[..., _R]], _cached_wrapper[_R]]: ...
179+
*,
180+
info: Literal[True],
181+
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
182+
@overload
183+
def cached(
184+
cache: MutableMapping[_KT, Any] | None,
185+
key: Callable[..., _KT],
186+
lock: AbstractContextManager[Any] | None,
187+
condition: _AbstractCondition | None,
188+
info: Literal[True],
189+
) -> Callable[[Callable[..., _R]], _cached_wrapper_info[_R]]: ...
181190

182191
@type_check_only
183192
class _cachedmethod_wrapper(Generic[_R]):
@@ -201,13 +210,22 @@ def cachedmethod(
201210
key: Callable[..., _KT] = ...,
202211
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
203212
condition: Callable[[Any], _AbstractCondition] | None = None,
204-
info: Literal[True] = ...,
205-
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ...
213+
info: Literal[False] = ...,
214+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper[_R]]: ...
206215
@overload
207216
def cachedmethod(
208217
cache: Callable[[Any], MutableMapping[_KT, Any]],
209218
key: Callable[..., _KT] = ...,
210219
lock: Callable[[Any], AbstractContextManager[Any]] | None = None,
211220
condition: Callable[[Any], _AbstractCondition] | None = None,
212-
info: Literal[False] = ...,
213-
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper[_R]]: ...
221+
*,
222+
info: Literal[True],
223+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ...
224+
@overload
225+
def cachedmethod(
226+
cache: Callable[[Any], MutableMapping[_KT, Any]],
227+
key: Callable[..., _KT],
228+
lock: Callable[[Any], AbstractContextManager[Any]] | None,
229+
condition: Callable[[Any], _AbstractCondition] | None,
230+
info: Literal[True],
231+
) -> Callable[[Callable[..., _R]], _cachedmethod_wrapper_info[_R]]: ...

0 commit comments

Comments
 (0)