* Support Python 3.14 removals. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-async-lru?expand=0&rev=10
126 lines
4.3 KiB
Diff
126 lines
4.3 KiB
Diff
From c2a83bb41ca6ffd964854d0fe9c6014e5356ad2c Mon Sep 17 00:00:00 2001
|
|
From: Lumir Balhar <lbalhar@redhat.com>
|
|
Date: Fri, 17 Jan 2025 14:57:03 +0100
|
|
Subject: [PATCH 01/20] Switch from asyncio.iscoroutinefunction to inspect for
|
|
Py 3.14+.
|
|
|
|
The former causes: DeprecationWarning:
|
|
'asyncio.iscoroutinefunction' is deprecated and slated for removal
|
|
in Python 3.16; use inspect.iscoroutinefunction() instead.
|
|
|
|
Fixes: https://github.com/aio-libs/async-lru/issues/635
|
|
---
|
|
async_lru/__init__.py | 8 +++++++-
|
|
tests/test_basic.py | 9 +++++----
|
|
2 files changed, 12 insertions(+), 5 deletions(-)
|
|
|
|
Index: async_lru-2.0.5/async_lru/__init__.py
|
|
===================================================================
|
|
--- async_lru-2.0.5.orig/async_lru/__init__.py
|
|
+++ async_lru-2.0.5/async_lru/__init__.py
|
|
@@ -1,7 +1,7 @@
|
|
import asyncio
|
|
import dataclasses
|
|
+import inspect
|
|
import sys
|
|
-from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined]
|
|
from functools import _CacheInfo, _make_key, partial, partialmethod
|
|
from typing import (
|
|
Any,
|
|
@@ -27,6 +27,9 @@ if sys.version_info >= (3, 11):
|
|
else:
|
|
from typing_extensions import Self
|
|
|
|
+if sys.version_info < (3, 14):
|
|
+ from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined]
|
|
+
|
|
|
|
__version__ = "2.0.5"
|
|
|
|
@@ -95,7 +98,8 @@ class _LRUCacheWrapper(Generic[_R]):
|
|
pass
|
|
# set __wrapped__ last so we don't inadvertently copy it
|
|
# from the wrapped function when updating __dict__
|
|
- self._is_coroutine = _is_coroutine
|
|
+ if sys.version_info < (3, 14):
|
|
+ self._is_coroutine = _is_coroutine
|
|
self.__wrapped__ = fn
|
|
self.__maxsize = maxsize
|
|
self.__typed = typed
|
|
@@ -262,7 +266,8 @@ class _LRUCacheWrapperInstanceMethod(Gen
|
|
pass
|
|
# set __wrapped__ last so we don't inadvertently copy it
|
|
# from the wrapped function when updating __dict__
|
|
- self._is_coroutine = _is_coroutine
|
|
+ if sys.version_info < (3, 14):
|
|
+ self._is_coroutine = _is_coroutine
|
|
self.__wrapped__ = wrapper.__wrapped__
|
|
self.__instance = instance
|
|
self.__wrapper = wrapper
|
|
@@ -299,14 +304,17 @@ def _make_wrapper(
|
|
while isinstance(origin, (partial, partialmethod)):
|
|
origin = origin.func
|
|
|
|
- if not asyncio.iscoroutinefunction(origin):
|
|
+ if not inspect.iscoroutinefunction(origin):
|
|
raise RuntimeError(f"Coroutine function is required, got {fn!r}")
|
|
|
|
# functools.partialmethod support
|
|
if hasattr(fn, "_make_unbound_method"):
|
|
fn = fn._make_unbound_method()
|
|
|
|
- return _LRUCacheWrapper(cast(_CB[_R], fn), maxsize, typed, ttl)
|
|
+ wrapper = _LRUCacheWrapper(cast(_CB[_R], fn), maxsize, typed, ttl)
|
|
+ if sys.version_info >= (3, 12):
|
|
+ wrapper = inspect.markcoroutinefunction(wrapper)
|
|
+ return wrapper
|
|
|
|
return wrapper
|
|
|
|
Index: async_lru-2.0.5/tests/test_basic.py
|
|
===================================================================
|
|
--- async_lru-2.0.5.orig/tests/test_basic.py
|
|
+++ async_lru-2.0.5/tests/test_basic.py
|
|
@@ -1,4 +1,5 @@
|
|
import asyncio
|
|
+import inspect
|
|
import platform
|
|
import sys
|
|
from functools import _CacheInfo, partial
|
|
@@ -27,7 +28,10 @@ async def test_alru_cache_deco(check_lru
|
|
async def coro() -> None:
|
|
pass
|
|
|
|
- assert asyncio.iscoroutinefunction(coro)
|
|
+ if sys.version_info >= (3, 12):
|
|
+ assert inspect.iscoroutinefunction(coro)
|
|
+ if sys.version_info < (3, 14):
|
|
+ assert asyncio.iscoroutinefunction(coro)
|
|
|
|
check_lru(coro, hits=0, misses=0, cache=0, tasks=0)
|
|
|
|
@@ -41,7 +45,10 @@ async def test_alru_cache_deco_called(ch
|
|
async def coro() -> None:
|
|
pass
|
|
|
|
- assert asyncio.iscoroutinefunction(coro)
|
|
+ if sys.version_info >= (3, 12):
|
|
+ assert inspect.iscoroutinefunction(coro)
|
|
+ if sys.version_info < (3, 14):
|
|
+ assert asyncio.iscoroutinefunction(coro)
|
|
|
|
check_lru(coro, hits=0, misses=0, cache=0, tasks=0)
|
|
|
|
@@ -56,7 +63,10 @@ async def test_alru_cache_fn_called(chec
|
|
|
|
coro_wrapped = alru_cache(coro)
|
|
|
|
- assert asyncio.iscoroutinefunction(coro_wrapped)
|
|
+ if sys.version_info >= (3, 12):
|
|
+ assert inspect.iscoroutinefunction(coro_wrapped)
|
|
+ if sys.version_info < (3, 14):
|
|
+ assert asyncio.iscoroutinefunction(coro)
|
|
|
|
check_lru(coro_wrapped, hits=0, misses=0, cache=0, tasks=0)
|
|
|