|
1 | 1 | from collections.abc import Awaitable, Callable, Generator |
2 | 2 | from functools import wraps |
3 | 3 | from typing import NewType, ParamSpec, TypeVar, cast, final |
| 4 | +from contextlib import AbstractAsyncContextManager |
4 | 5 |
|
5 | 6 | # Try to use anyio.Lock, fall back to asyncio.Lock |
| 7 | +# Note: anyio is required for proper trio support |
6 | 8 | try: |
7 | 9 | import anyio # noqa: WPS433 |
8 | 10 | except ImportError: # pragma: no cover |
9 | 11 | import asyncio # noqa: WPS433 |
10 | 12 |
|
11 | | - Lock = asyncio.Lock |
| 13 | + Lock:AbstractAsyncContextManager = asyncio.Lock |
12 | 14 | else: |
13 | | - Lock = anyio.Lock |
| 15 | + Lock:AbstractAsyncContextManager = anyio.Lock |
14 | 16 |
|
15 | 17 | _ValueType = TypeVar('_ValueType') |
16 | 18 | _AwaitableT = TypeVar('_AwaitableT', bound=Awaitable) |
@@ -55,6 +57,10 @@ class ReAwaitable: |
55 | 57 |
|
56 | 58 | We try to make this type transparent. |
57 | 59 | 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. |
58 | 64 |
|
59 | 65 | """ |
60 | 66 |
|
@@ -138,7 +144,10 @@ def reawaitable( |
138 | 144 | ... return await instance + await instance + await instance |
139 | 145 |
|
140 | 146 | >>> 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. |
142 | 151 | """ |
143 | 152 |
|
144 | 153 | @wraps(coro) |
|
0 commit comments