Skip to content

Commit ffa8ec8

Browse files
committed
Use inspect to determine anyio.to_thread.run_sync kwargs
1 parent fb6386d commit ffa8ec8

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

asyncer/_compat.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
import sys
2-
from typing import Callable, Tuple, TypeVar, Union
1+
import inspect
2+
from typing import Callable, TypeVar, Union
33

44
import anyio
55
import anyio.to_thread
66
from anyio import CapacityLimiter
77
from typing_extensions import TypeVarTuple, Unpack
88

9-
if sys.version_info < (3, 10):
10-
from importlib_metadata import version as get_version
11-
else:
12-
from importlib.metadata import version as get_version
13-
14-
ANYIO_VERSION: Tuple[int, ...] = tuple(
15-
int(num) for num in get_version("anyio").split(".")[:3]
16-
)
17-
189
T_Retval = TypeVar("T_Retval")
1910
PosArgsT = TypeVarTuple("PosArgsT")
2011

2112

2213
# AnyIO 4.1.0 renamed cancellable to abandon_on_cancel
23-
if ANYIO_VERSION >= (4, 1):
14+
if "abandon_on_cancel" in inspect.getfullargspec(anyio.to_thread.run_sync).kwonlyargs:
2415

2516
async def run_sync(
2617
func: Callable[[Unpack[PosArgsT]], T_Retval],

pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ classifiers = [
3232
]
3333
dependencies = [
3434
"anyio >=3.4.0,<5.0",
35-
"importlib-metadata >=4.6; python_version < '3.10'",
36-
"typing_extensions >=4.8.0; python_version < '3.10'",
35+
"typing_extensions >=4.8.0; python_version < '3.10'"
3736
]
3837

3938
[project.urls]

0 commit comments

Comments
 (0)