Skip to content

Commit 0227077

Browse files
committed
Move anyio kwarg check to constant
This ensures the check is only performed once on import, whilst retaining a static function definition.
1 parent 78626db commit 0227077

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

asyncer/_compat.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
T_Retval = TypeVar("T_Retval")
1010
PosArgsT = TypeVarTuple("PosArgsT")
1111

12+
# Use abandon_on_cancel if available
13+
RUN_SYNC_AOC = (
14+
"abandon_on_cancel" in inspect.getfullargspec(anyio.to_thread.run_sync).kwonlyargs
15+
)
16+
1217

1318
async def run_sync(
1419
func: Callable[[Unpack[PosArgsT]], T_Retval],
@@ -17,10 +22,7 @@ async def run_sync(
1722
limiter: Union[CapacityLimiter, None] = None,
1823
) -> T_Retval:
1924
# AnyIO 4.1.0 renamed cancellable to abandon_on_cancel
20-
if (
21-
"abandon_on_cancel"
22-
in inspect.getfullargspec(anyio.to_thread.run_sync).kwonlyargs
23-
):
25+
if RUN_SYNC_AOC:
2426
return await anyio.to_thread.run_sync(
2527
func, *args, abandon_on_cancel=abandon_on_cancel, limiter=limiter
2628
)

0 commit comments

Comments
 (0)