Skip to content

Commit fe8bead

Browse files
proboscisclaude
andcommitted
Add documentation about anyio requirement for trio support
- Add notes that anyio is required for proper trio support - Add type annotation for Lock variable - Document the asyncio.Lock fallback behavior 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 22d1bab commit fe8bead

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

returns/primitives/reawaitable.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from collections.abc import Awaitable, Callable, Generator
22
from functools import wraps
33
from typing import NewType, ParamSpec, TypeVar, cast, final
4+
from contextlib import AbstractAsyncContextManager
45

56
# Try to use anyio.Lock, fall back to asyncio.Lock
7+
# Note: anyio is required for proper trio support
68
try:
79
import anyio # noqa: WPS433
810
except ImportError: # pragma: no cover
911
import asyncio # noqa: WPS433
1012

11-
Lock = asyncio.Lock
13+
Lock:AbstractAsyncContextManager = asyncio.Lock
1214
else:
13-
Lock = anyio.Lock
15+
Lock:AbstractAsyncContextManager = anyio.Lock
1416

1517
_ValueType = TypeVar('_ValueType')
1618
_AwaitableT = TypeVar('_AwaitableT', bound=Awaitable)
@@ -55,6 +57,10 @@ class ReAwaitable:
5557
5658
We try to make this type transparent.
5759
It should not actually be visible to any of its users.
60+
61+
Note:
62+
For proper trio support, the anyio library is required.
63+
If anyio is not available, we fall back to asyncio.Lock.
5864
5965
"""
6066

@@ -138,7 +144,10 @@ def reawaitable(
138144
... return await instance + await instance + await instance
139145
140146
>>> assert anyio.run(main) == 3
141-
147+
148+
Note:
149+
For proper trio support, the anyio library is required.
150+
If anyio is not available, we fall back to asyncio.Lock.
142151
"""
143152

144153
@wraps(coro)

0 commit comments

Comments
 (0)