Skip to content

Commit b0a44bc

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

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
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/*
@@ -23,4 +23,4 @@ exclude_lines =
2323
def __init__
2424
def __aenter__
2525
def __aexit__
26-
->exit
26+
->exit

returns/primitives/reawaitable.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
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
# pragma: no cover
89
class AsyncLock(Protocol):
910
"""A protocol for an asynchronous lock."""
11+
1012
def __init__(self) -> None: ...
1113
async def __aenter__(self) -> None: ...
1214
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: ...
1315

1416

1517
# Define context types as literals
16-
AsyncContext = Literal["asyncio", "trio", "unknown"]
18+
AsyncContext = Literal['asyncio', 'trio', 'unknown']
1719

1820

1921
# Functions for detecting async context - these are excluded from coverage
@@ -61,10 +63,10 @@ def _is_in_trio_context() -> bool:
6163
# Early return if trio is not available
6264
if not has_trio:
6365
return False
64-
66+
6567
# Import trio here since we already checked it's available
6668
import trio
67-
69+
6870
try:
6971
# Will raise RuntimeError if not in trio context
7072
trio.lowlevel.current_task()
@@ -82,9 +84,9 @@ def detect_async_context() -> AsyncContext: # pragma: no cover
8284
"""
8385
# This branch is only taken when anyio is not installed
8486
if not has_anyio or not _is_in_trio_context():
85-
return "asyncio"
87+
return 'asyncio'
8688

87-
return "trio"
89+
return 'trio'
8890

8991

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

148152
def __await__(self) -> Generator[None, None, _ValueType]:
149153
"""
@@ -193,14 +197,14 @@ def _create_lock(self) -> AsyncLock:
193197
"""Create the appropriate lock based on the current async context."""
194198
context = detect_async_context()
195199

196-
if context == "trio" and has_anyio:
200+
if context == 'trio' and has_anyio:
197201
try:
198202
import anyio
199203
except Exception:
200204
# Just continue to asyncio if anyio import fails
201205
return asyncio.Lock()
202206
return anyio.Lock()
203-
207+
204208
# For asyncio or unknown contexts
205209
return asyncio.Lock()
206210

@@ -256,4 +260,4 @@ def decorator(
256260
) -> _AwaitableT:
257261
return ReAwaitable(coro(*args, **kwargs)) # type: ignore[return-value]
258262

259-
return decorator
263+
return decorator

tests/test_primitives/test_reawaitable/test_reawaitable_full_coverage.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import pytest
2-
from unittest.mock import patch, MagicMock
32

43
from returns.primitives.reawaitable import (
5-
ReAwaitable,
4+
ReAwaitable,
65
reawaitable,
76
)
87

@@ -17,14 +16,14 @@ async def test_reawaitable_lock_creation():
1716
"""Test the _create_lock method for different contexts."""
1817
# Create a ReAwaitable instance
1918
instance = ReAwaitable(_test_coro())
20-
19+
2120
# Test the lock is initially None
2221
assert instance._lock is None
23-
22+
2423
# Await to trigger lock creation
2524
result = await instance
2625
assert result == 'value'
27-
26+
2827
# Verify lock is created
2928
assert instance._lock is not None
3029

@@ -44,10 +43,10 @@ async def test_reawaitable_decorator():
4443
"""Test the reawaitable decorator."""
4544
# Call the decorated function
4645
result = _test_multiply(5)
47-
46+
4847
# Verify it can be awaited multiple times
4948
assert await result == 10
5049
assert await result == 10 # Should use cached value
5150

5251

53-
# Tests removed as we're using pragmas now
52+
# Tests removed as we're using pragmas now

tests/test_primitives/test_reawaitable/test_reawaitable_lock.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import pytest
2-
import anyio
32

43
from returns.primitives.reawaitable import (
54
ReAwaitable,
6-
detect_async_context,
75
_is_in_trio_context,
6+
detect_async_context,
87
)
98

109

@@ -18,17 +17,17 @@ async def test_reawaitable_create_lock():
1817
"""Test that ReAwaitable correctly creates the lock when needed."""
1918
# Create ReAwaitable instance
2019
reawait = ReAwaitable(_test_coro())
21-
20+
2221
# The lock should be None initially
2322
assert reawait._lock is None
24-
23+
2524
# Await the coroutine once
2625
result1 = await reawait
27-
26+
2827
# The lock should be created
2928
assert reawait._lock is not None
3029
assert result1 == 'test'
31-
30+
3231
# Await again, should use the same lock
3332
result2 = await reawait
3433
assert result2 == 'test'
@@ -49,4 +48,4 @@ async def test_is_in_trio_context():
4948
# we just check the function runs without errors
5049
result = _is_in_trio_context()
5150
# Result will depend on which backend anyio is using
52-
assert isinstance(result, bool)
51+
assert isinstance(result, bool)

0 commit comments

Comments
 (0)