42
42
_T = TypeVar ("_T" )
43
43
_R = TypeVar ("_R" )
44
44
_P = ParamSpec ("_P" )
45
- _Coro = Coroutine [Any , Any , _R ]
46
- _CB = Callable [_P , _Coro [_R ]]
47
- _CBP = Union [_CB [_P , _R ], "partial[_Coro[_R]]" , "partialmethod[_Coro[_R]]" ]
48
45
49
46
50
47
@final
@@ -71,7 +68,7 @@ def cancel(self) -> None:
71
68
class _LRUCacheWrapper (Generic [_P , _R ]):
72
69
def __init__ (
73
70
self ,
74
- fn : _CB [_P , _R ],
71
+ fn : Callable [_P , Coroutine [ Any , Any , _R ] ],
75
72
maxsize : Optional [int ],
76
73
typed : bool ,
77
74
ttl : Optional [float ],
@@ -299,8 +296,8 @@ def _make_wrapper(
299
296
maxsize : Optional [int ],
300
297
typed : bool ,
301
298
ttl : Optional [float ] = None ,
302
- ) -> Callable [[_CBP [_P , _R ]], _LRUCacheWrapper [_P , _R ]]:
303
- def wrapper (fn : _CBP [_P , _R ]) -> _LRUCacheWrapper [_P , _R ]:
299
+ ) -> Callable [[Callable [_P , Coroutine [ Any , Any , _R ] ]], _LRUCacheWrapper [_P , _R ]]:
300
+ def wrapper (fn : Callable [_P , Coroutine [ Any , Any , _R ] ]) -> _LRUCacheWrapper [_P , _R ]:
304
301
origin = fn
305
302
306
303
while isinstance (origin , (partial , partialmethod )):
@@ -313,7 +310,7 @@ def wrapper(fn: _CBP[_P, _R]) -> _LRUCacheWrapper[_P, _R]:
313
310
if hasattr (fn , "_make_unbound_method" ):
314
311
fn = fn ._make_unbound_method ()
315
312
316
- return _LRUCacheWrapper (cast ( _CB [ _P , _R ], fn ) , maxsize , typed , ttl )
313
+ return _LRUCacheWrapper (fn , maxsize , typed , ttl )
317
314
318
315
return wrapper
319
316
@@ -324,32 +321,33 @@ def alru_cache(
324
321
typed : bool = False ,
325
322
* ,
326
323
ttl : Optional [float ] = None ,
327
- ) -> Callable [[_CBP [_P , _R ]], _LRUCacheWrapper [_P , _R ]]:
324
+ ) -> Callable [[Callable [_P , Coroutine [ Any , Any , _R ] ]], _LRUCacheWrapper [_P , _R ]]:
328
325
...
329
326
330
327
331
328
@overload
332
- def alru_cache (
333
- maxsize : _CBP [_P , _R ],
329
+ def alru_cache ( # type: ignore[misc]
330
+ maxsize : Callable [_P , Coroutine [ Any , Any , _R ] ],
334
331
/ ,
335
332
) -> _LRUCacheWrapper [_P , _R ]:
336
333
...
337
334
338
335
339
336
def alru_cache (
340
- maxsize : Union [Optional [int ], _CBP [_P , _R ]] = 128 ,
337
+ maxsize : Union [Optional [int ], Callable [_P , Coroutine [ Any , Any , _R ] ]] = 128 ,
341
338
typed : bool = False ,
342
339
* ,
343
340
ttl : Optional [float ] = None ,
344
341
) -> Union [
345
- Callable [[_CBP [_P , _R ]], _LRUCacheWrapper [_P , _R ]], _LRUCacheWrapper [_P , _R ]
342
+ Callable [[Callable [_P , Coroutine [ Any , Any , _R ] ]], _LRUCacheWrapper [_P , _R ]], _LRUCacheWrapper [_P , _R ]
346
343
]:
347
344
if maxsize is None or isinstance (maxsize , int ):
348
345
return _make_wrapper (maxsize , typed , ttl )
349
346
else :
350
347
fn = maxsize
351
348
352
- if callable (fn ) or hasattr (fn , "_make_unbound_method" ):
349
+ # partialmethod is not callable() at runtime.
350
+ if callable (fn ) or hasattr (fn , "_make_unbound_method" ): # type: ignore[unreachable]
353
351
return _make_wrapper (128 , False , None )(fn )
354
352
355
353
raise NotImplementedError (f"{ fn !r} decorating is not supported" )
0 commit comments