From c2a83bb41ca6ffd964854d0fe9c6014e5356ad2c Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Fri, 17 Jan 2025 14:57:03 +0100 Subject: [PATCH 01/10] 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(-) diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 228ebad..9b88faf 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -27,6 +27,12 @@ else: from typing_extensions import Self +if sys.version_info >= (3, 14): + import inspect + iscoroutinefunction = inspect.iscoroutinefunction +else: + iscoroutinefunction = asyncio.iscoroutinefunction + __version__ = "2.0.4" @@ -299,7 +305,7 @@ def wrapper(fn: _CBP[_R]) -> _LRUCacheWrapper[_R]: while isinstance(origin, (partial, partialmethod)): origin = origin.func - if not asyncio.iscoroutinefunction(origin): + if not iscoroutinefunction(origin): raise RuntimeError(f"Coroutine function is required, got {fn!r}") # functools.partialmethod support diff --git a/tests/test_basic.py b/tests/test_basic.py index acc57a2..3898f49 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,4 +1,5 @@ import asyncio +import inspect import platform import sys from functools import _CacheInfo, partial @@ -6,7 +7,7 @@ import pytest -from async_lru import _CacheParameters, alru_cache +from async_lru import _CacheParameters, alru_cache, iscoroutinefunction def test_alru_cache_not_callable() -> None: @@ -27,7 +28,7 @@ async def test_alru_cache_deco(check_lru: Callable[..., None]) -> None: async def coro() -> None: pass - assert asyncio.iscoroutinefunction(coro) + assert iscoroutinefunction(coro) check_lru(coro, hits=0, misses=0, cache=0, tasks=0) @@ -41,7 +42,7 @@ async def test_alru_cache_deco_called(check_lru: Callable[..., None]) -> None: async def coro() -> None: pass - assert asyncio.iscoroutinefunction(coro) + assert iscoroutinefunction(coro) check_lru(coro, hits=0, misses=0, cache=0, tasks=0) @@ -56,7 +57,7 @@ async def coro() -> None: coro_wrapped = alru_cache(coro) - assert asyncio.iscoroutinefunction(coro_wrapped) + assert iscoroutinefunction(coro_wrapped) check_lru(coro_wrapped, hits=0, misses=0, cache=0, tasks=0) From 1bdaf3834cf812bb7985737dbfc56be8a3e95009 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:37:33 +0000 Subject: [PATCH 02/10] Ignore --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index b7babe0..f03c821 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,6 +74,7 @@ known_first_party=async_lru addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=async_lru --cov=tests/ --cov-report=term --cov-report=html filterwarnings = error + ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio.plugin testpaths = tests/ junit_family=xunit2 asyncio_mode=auto From 597a4b679288e4c8a153f9fff10591161a611668 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:39:04 +0000 Subject: [PATCH 03/10] Update __init__.py --- async_lru/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 9b88faf..4a8f902 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -1,5 +1,6 @@ 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 @@ -28,7 +29,6 @@ from typing_extensions import Self if sys.version_info >= (3, 14): - import inspect iscoroutinefunction = inspect.iscoroutinefunction else: iscoroutinefunction = asyncio.iscoroutinefunction From 90f7b0906d6ce1077606cd3372a34f601b3a4733 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:43:08 +0000 Subject: [PATCH 04/10] Update __init__.py --- async_lru/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/async_lru/__init__.py b/async_lru/__init__.py index 4a8f902..d66fb2d 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -1,6 +1,5 @@ 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 @@ -29,6 +28,8 @@ from typing_extensions import Self if sys.version_info >= (3, 14): + import inspect + iscoroutinefunction = inspect.iscoroutinefunction else: iscoroutinefunction = asyncio.iscoroutinefunction From 5e7bb22c8b9a0a35784493ac0b1a00fffeda4f82 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:43:32 +0000 Subject: [PATCH 05/10] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index f03c821..bbefc19 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,7 +74,7 @@ known_first_party=async_lru addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=async_lru --cov=tests/ --cov-report=term --cov-report=html filterwarnings = error - ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio.plugin + ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2 asyncio_mode=auto From 8a2db094cfae28d36914a7921dcf68983020ccf7 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:45:26 +0000 Subject: [PATCH 06/10] Update __init__.py --- async_lru/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/async_lru/__init__.py b/async_lru/__init__.py index d66fb2d..645872f 100644 --- a/async_lru/__init__.py +++ b/async_lru/__init__.py @@ -1,5 +1,6 @@ import asyncio import dataclasses +import inspect # noqa: F401 import sys from asyncio.coroutines import _is_coroutine # type: ignore[attr-defined] from functools import _CacheInfo, _make_key, partial, partialmethod @@ -28,8 +29,6 @@ from typing_extensions import Self if sys.version_info >= (3, 14): - import inspect - iscoroutinefunction = inspect.iscoroutinefunction else: iscoroutinefunction = asyncio.iscoroutinefunction From ce82b1cd591d730fa16828cae4d9b290a1879dcd Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:45:55 +0000 Subject: [PATCH 07/10] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index bbefc19..d6c0a11 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,7 +74,7 @@ known_first_party=async_lru addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=async_lru --cov=tests/ --cov-report=term --cov-report=html filterwarnings = error - ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:.*'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2 asyncio_mode=auto From 1438ca2854e1da040d6fafd6cdffbc8ae69cd3c0 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:51:30 +0000 Subject: [PATCH 08/10] Update setup.cfg --- setup.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index d6c0a11..19719ae 100644 --- a/setup.cfg +++ b/setup.cfg @@ -74,7 +74,8 @@ known_first_party=async_lru addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=async_lru --cov=tests/ --cov-report=term --cov-report=html filterwarnings = error - ignore:.*'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.set_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2 asyncio_mode=auto From 1bb0caaf98863ce94371445a237718fe8ab46d2d Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:54:27 +0000 Subject: [PATCH 09/10] Update setup.cfg --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 19719ae..ab08cba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,7 +75,7 @@ addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=asy filterwarnings = error ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio - ignore:'asyncio.set_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.set_event_loop' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2 asyncio_mode=auto From 3f84c3b2befcf46a118f46c5cf89452b783a08ab Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 2 Feb 2025 22:56:19 +0000 Subject: [PATCH 10/10] Update setup.cfg --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index ab08cba..95fde29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,6 +75,7 @@ addopts= -s --keep-duplicates --cache-clear --verbose --no-cov-on-fail --cov=asy filterwarnings = error ignore:'asyncio.get_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio + ignore:'asyncio.set_event_loop_policy' is deprecated:DeprecationWarning:pytest_asyncio ignore:'asyncio.set_event_loop' is deprecated:DeprecationWarning:pytest_asyncio testpaths = tests/ junit_family=xunit2