|
1 | 1 | import asyncio |
2 | 2 | import dataclasses |
| 3 | +import inspect |
3 | 4 | import sys |
4 | | -from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] |
5 | 5 | from functools import _CacheInfo, _make_key, partial, partialmethod |
6 | 6 | from typing import ( |
7 | 7 | Any, |
|
27 | 27 | else: |
28 | 28 | from typing_extensions import Self |
29 | 29 |
|
| 30 | +if sys.version_info < (3, 14): |
| 31 | + from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] |
| 32 | + |
30 | 33 |
|
31 | 34 | __version__ = "2.0.5" |
32 | 35 |
|
@@ -95,7 +98,8 @@ def __init__( |
95 | 98 | pass |
96 | 99 | # set __wrapped__ last so we don't inadvertently copy it |
97 | 100 | # from the wrapped function when updating __dict__ |
98 | | - self._is_coroutine = _is_coroutine |
| 101 | + if sys.version_info < (3, 14): |
| 102 | + self._is_coroutine = _is_coroutine |
99 | 103 | self.__wrapped__ = fn |
100 | 104 | self.__maxsize = maxsize |
101 | 105 | self.__typed = typed |
@@ -262,7 +266,8 @@ def __init__( |
262 | 266 | pass |
263 | 267 | # set __wrapped__ last so we don't inadvertently copy it |
264 | 268 | # from the wrapped function when updating __dict__ |
265 | | - self._is_coroutine = _is_coroutine |
| 269 | + if sys.version_info < (3, 14): |
| 270 | + self._is_coroutine = _is_coroutine |
266 | 271 | self.__wrapped__ = wrapper.__wrapped__ |
267 | 272 | self.__instance = instance |
268 | 273 | self.__wrapper = wrapper |
@@ -299,14 +304,17 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]: |
299 | 304 | while isinstance(origin, (partial, partialmethod)): |
300 | 305 | origin = origin.func |
301 | 306 |
|
302 | | - if not asyncio.iscoroutinefunction(origin): |
| 307 | + if not inspect.iscoroutinefunction(origin): |
303 | 308 | raise RuntimeError(f"Coroutine function is required, got {fn!r}") |
304 | 309 |
|
305 | 310 | # functools.partialmethod support |
306 | 311 | if hasattr(fn, "_make_unbound_method"): |
307 | 312 | fn = fn._make_unbound_method() |
308 | 313 |
|
309 | | - return _LRUCacheWrapper(cast(_CB[_R], fn), maxsize, typed, ttl) |
| 314 | + wrapper = _LRUCacheWrapper(cast(_CB[_R], fn), maxsize, typed, ttl) |
| 315 | + if sys.version_info >= (3, 12): |
| 316 | + wrapper = inspect.markcoroutinefunction(wrapper) |
| 317 | + return wrapper |
310 | 318 |
|
311 | 319 | return wrapper |
312 | 320 |
|
|
0 commit comments