Skip to content

Commit a396766

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
1 parent 5847569 commit a396766

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

returns/primitives/reawaitable.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ...
1717
import asyncio # noqa: WPS433
1818
from enum import Enum, auto
1919

20+
2021
class AsyncContext(Enum):
2122
"""Enum representing different async context types."""
22-
23+
2324
ASYNCIO = auto()
2425
TRIO = auto()
2526
UNKNOWN = auto()
2627

28+
2729
# Check for anyio and trio availability
2830
try:
2931
import anyio # noqa: WPS433
32+
3033
has_anyio = True
3134
try:
3235
import trio # noqa: WPS433
36+
3337
has_trio = True
3438
except ImportError: # pragma: no cover
3539
has_trio = False
@@ -40,13 +44,13 @@ class AsyncContext(Enum):
4044

4145
def detect_async_context() -> AsyncContext:
4246
"""Detect which async context we're currently running in.
43-
47+
4448
Returns:
4549
AsyncContext: The current async context type
4650
"""
4751
if not has_anyio: # pragma: no cover
4852
return AsyncContext.ASYNCIO
49-
53+
5054
if has_trio:
5155
try:
5256
# Check if we're in a trio context
@@ -56,10 +60,11 @@ def detect_async_context() -> AsyncContext:
5660
except (RuntimeError, AttributeError):
5761
# Not in a trio context or trio API changed
5862
pass
59-
63+
6064
# Default to asyncio
6165
return AsyncContext.ASYNCIO
6266

67+
6368
_ValueType = TypeVar('_ValueType')
6469
_AwaitableT = TypeVar('_AwaitableT', bound=Awaitable)
6570
_Ps = ParamSpec('_Ps')
@@ -165,10 +170,10 @@ def __repr__(self) -> str:
165170
def _create_lock(self) -> AsyncLock:
166171
"""Create the appropriate lock based on the current async context."""
167172
context = detect_async_context()
168-
173+
169174
if context == AsyncContext.TRIO and has_anyio:
170175
return anyio.Lock()
171-
176+
172177
# For ASYNCIO or UNKNOWN contexts
173178
return asyncio.Lock()
174179

0 commit comments

Comments
 (0)