Skip to content

Commit 01a28c5

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
1 parent 69c3d8b commit 01a28c5

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

.coveragerc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[run]
2-
omit =
2+
omit =
33
returns/contrib/mypy/*
44
returns/contrib/pytest/*.py
55
returns/contrib/hypothesis/*
@@ -12,4 +12,4 @@ exclude_lines =
1212
if not has_trio
1313
if context == "trio" and has_anyio
1414
except RuntimeError:
15-
except Exception:
15+
except Exception:

returns/primitives/reawaitable.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
# Always import asyncio
2+
import asyncio
13
from collections.abc import Awaitable, Callable, Generator
24
from functools import wraps
35
from typing import Literal, NewType, ParamSpec, Protocol, TypeVar, cast, final
4-
# Always import asyncio
5-
import asyncio
6+
67

78
class AsyncLock(Protocol):
89
"""A protocol for an asynchronous lock."""
@@ -15,7 +16,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ...
1516

1617

1718
# Define context types as literals
18-
AsyncContext = Literal["asyncio", "trio", "unknown"]
19+
AsyncContext = Literal['asyncio', 'trio', 'unknown']
1920

2021

2122
# pragma: no cover
@@ -63,10 +64,10 @@ def _is_in_trio_context() -> bool:
6364
# Early return if trio is not available
6465
if not has_trio:
6566
return False
66-
67+
6768
# Import trio here since we already checked it's available
6869
import trio
69-
70+
7071
try:
7172
# Will raise RuntimeError if not in trio context
7273
trio.lowlevel.current_task()
@@ -84,9 +85,9 @@ def detect_async_context() -> AsyncContext:
8485
"""
8586
# This branch is only taken when anyio is not installed
8687
if not has_anyio or not _is_in_trio_context():
87-
return "asyncio"
88+
return 'asyncio'
8889

89-
return "trio"
90+
return 'trio'
9091

9192

9293
_ValueType = TypeVar('_ValueType')
@@ -145,7 +146,9 @@ def __init__(self, coro: Awaitable[_ValueType]) -> None:
145146
"""We need just an awaitable to work with."""
146147
self._coro = coro
147148
self._cache: _ValueType | _Sentinel = _sentinel
148-
self._lock: AsyncLock | None = None # Will be created lazily based on the backend
149+
self._lock: AsyncLock | None = (
150+
None # Will be created lazily based on the backend
151+
)
149152

150153
def __await__(self) -> Generator[None, None, _ValueType]:
151154
"""
@@ -195,14 +198,14 @@ def _create_lock(self) -> AsyncLock:
195198
"""Create the appropriate lock based on the current async context."""
196199
context = detect_async_context()
197200

198-
if context == "trio" and has_anyio:
201+
if context == 'trio' and has_anyio:
199202
try:
200203
import anyio
201204
except Exception:
202205
# Just continue to asyncio if anyio import fails
203206
return asyncio.Lock()
204207
return anyio.Lock()
205-
208+
206209
# For asyncio or unknown contexts
207210
return asyncio.Lock()
208211

@@ -257,4 +260,4 @@ def decorator(
257260
) -> _AwaitableT:
258261
return ReAwaitable(coro(*args, **kwargs)) # type: ignore[return-value]
259262

260-
return decorator
263+
return decorator

0 commit comments

Comments
 (0)