Skip to content

Commit 4549f17

Browse files
authored
Fixed warnings for inmemory broker. (#125)
1 parent fb58c11 commit 4549f17

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

taskiq/brokers/inmemory_broker.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import inspect
33
from collections import OrderedDict
44
from concurrent.futures import ThreadPoolExecutor
5-
from typing import Any, AsyncGenerator, Callable, Optional, Set, TypeVar, get_type_hints
5+
from typing import Any, AsyncGenerator, Set, TypeVar, get_type_hints
66

77
from taskiq_dependencies import DependencyGraph
88

@@ -88,22 +88,16 @@ class InMemoryBroker(AsyncBroker):
8888
It's useful for local development, if you don't want to setup real broker.
8989
"""
9090

91-
def __init__( # noqa: WPS211
91+
def __init__(
9292
self,
9393
sync_tasks_pool_size: int = 4,
9494
max_stored_results: int = 100,
9595
cast_types: bool = True,
96-
result_backend: Optional[AsyncResultBackend[Any]] = None,
97-
task_id_generator: Optional[Callable[[], str]] = None,
9896
max_async_tasks: int = 30,
9997
) -> None:
100-
if result_backend is None:
101-
result_backend = InmemoryResultBackend(
102-
max_stored_results=max_stored_results,
103-
)
104-
super().__init__(
105-
result_backend=result_backend,
106-
task_id_generator=task_id_generator,
98+
super().__init__()
99+
self.result_backend = InmemoryResultBackend(
100+
max_stored_results=max_stored_results,
107101
)
108102
self.executor = ThreadPoolExecutor(sync_tasks_pool_size)
109103
self.receiver = Receiver(

tests/cli/worker/test_receiver.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import asyncio
22
from concurrent.futures import ThreadPoolExecutor
3-
from typing import Any, AsyncGenerator, Callable, List, Optional, TypeVar
3+
from typing import Any, AsyncGenerator, List, Optional, TypeVar
44

55
import pytest
66
from taskiq_dependencies import Depends
77

88
from taskiq.abc.broker import AsyncBroker
99
from taskiq.abc.middleware import TaskiqMiddleware
10-
from taskiq.abc.result_backend import AsyncResultBackend
1110
from taskiq.brokers.inmemory_broker import InMemoryBroker
1211
from taskiq.message import TaskiqMessage
1312
from taskiq.receiver import Receiver
@@ -17,15 +16,8 @@
1716

1817

1918
class BrokerForTests(InMemoryBroker):
20-
def __init__(
21-
self,
22-
result_backend: "Optional[AsyncResultBackend[_T]]" = None,
23-
task_id_generator: Optional[Callable[[], str]] = None,
24-
) -> None:
25-
super().__init__(
26-
result_backend=result_backend,
27-
task_id_generator=task_id_generator,
28-
)
19+
def __init__(self) -> None:
20+
super().__init__()
2921
self.to_send: "List[TaskiqMessage]" = []
3022

3123
async def listen(self) -> AsyncGenerator[bytes, None]:
@@ -142,8 +134,7 @@ def on_error(
142134
def test_func() -> None:
143135
raise ValueError()
144136

145-
broker = InMemoryBroker()
146-
broker.add_middlewares(_TestMiddleware())
137+
broker = InMemoryBroker().with_middlewares(_TestMiddleware())
147138
receiver = get_receiver(broker)
148139

149140
result = await receiver.run_task(

0 commit comments

Comments
 (0)