Skip to content

Commit e7c499c

Browse files
committed
solve linting failures
1 parent 6e5970a commit e7c499c

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

libp2p/tools/anyio_service/anyio_service.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ def __init__(self, service: ServiceAPI) -> None:
204204
self._total_task_count = 0
205205
self._done_task_count = 0
206206

207-
self._started = anyio.Event()
208-
self._cancelled = anyio.Event()
209-
self._finished = anyio.Event()
207+
self._started = anyio.create_event()
208+
self._cancelled = anyio.create_event()
209+
self._finished = anyio.create_event()
210210

211-
self._run_lock = anyio.Lock()
211+
self._run_lock = anyio.create_lock()
212212
self._task_group: Optional[anyio.abc.TaskGroup] = None
213213

214214
def __str__(self) -> str:
@@ -297,11 +297,19 @@ async def _run_and_manage_task(self, task: TaskAPI) -> None:
297297

298298
# Handle ExceptionGroup if multiple exceptions occurred
299299
if len(self._errors) > 1:
300-
exceptions = [exc_value.with_traceback(exc_tb) for exc_type, exc_value, exc_tb in self._errors]
300+
exceptions = [
301+
exc_value.with_traceback(exc_tb)
302+
for exc_type, exc_value, exc_tb in self._errors
303+
]
301304
if sys.version_info >= (3, 11):
302305
raise ExceptionGroup("Multiple exceptions occurred", exceptions)
303306
else:
304-
raise RuntimeError("; ".join(f"{exc_type.__name__}: {str(exc_value)}" for exc_type, exc_value, exc_tb in self._errors))
307+
raise RuntimeError(
308+
"; ".join(
309+
f"{exc_type.__name__}: {str(exc_value)}"
310+
for exc_type, exc_value, exc_tb in self._errors
311+
)
312+
)
305313

306314
@classmethod
307315
async def run_service(cls, service: ServiceAPI) -> None:

tests/core/tools/anyio_service/test_anyio_service.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import sys
44

55
if sys.version_info >= (3, 11):
6-
from builtins import ExceptionGroup
6+
from builtins import (
7+
ExceptionGroup,
8+
)
79
else:
810
from exceptiongroup import ExceptionGroup
911

@@ -12,8 +14,6 @@
1214
AnyioManager,
1315
as_service,
1416
background_anyio_service,
15-
DaemonTaskExit,
16-
LifecycleError,
1717
)
1818

1919
@pytest.mark.anyio
@@ -39,7 +39,10 @@ async def run(self):
3939

4040
with pytest.raises(ExceptionGroup) as exc_info:
4141
await manager.run()
42-
assert any(isinstance(e, RuntimeError) and str(e) == "Service error" for e in exc_info.value.exceptions)
42+
assert any(
43+
isinstance(e, RuntimeError) and str(e) == "Service error"
44+
for e in exc_info.value.exceptions
45+
)
4346

4447
@pytest.mark.anyio
4548
async def test_task_management():
@@ -49,7 +52,6 @@ async def test_task_management():
4952
async def TaskService(manager):
5053
async def task_fn():
5154
task_event.set()
52-
manager.cancel()
5355

5456
manager.run_task(task_fn)
5557
await manager.wait_finished()
@@ -58,7 +60,6 @@ async def task_fn():
5860
with anyio.fail_after(0.1):
5961
await task_event.wait()
6062

61-
6263
@pytest.mark.anyio
6364
async def test_cancellation_and_cleanup():
6465
class CancellableService(Service):

0 commit comments

Comments
 (0)