Loading .pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ repos: - pydocstyle[toml] - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.961 rev: v0.991 hooks: - id: mypy args: [--follow-imports=silent] Loading kilter/service/runner.py +8 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ The primary class in this module (`Runner`) is intended to be used with an from __future__ import annotations import logging from collections.abc import AsyncGenerator from warnings import warn Loading @@ -27,6 +28,7 @@ from kilter.protocol.messages import ProtocolFlags from .session import * from .util import Broadcast from .util import qualname MessageChannel = anyio.abc.ObjectStream[Message] Sender = AsyncGenerator[None, Message] Loading Loading @@ -219,9 +221,13 @@ async def _runner( async with session: assert isinstance(session.broadcast, _Broadcast) session.broadcast.task_status = task_status try: final_resp = await fltr(session) except Exception: logging.exception(f"error in filter {qualname(fltr)}") final_resp = TemporaryFailure() if not isinstance(final_resp, _VALID_FINAL_RESPONSES): warn(f"expected a final response from {fltr}, got {final_resp}") warn(f"expected a valid response from {qualname(fltr)}, got {final_resp}") final_resp = TemporaryFailure() async with anyio.create_task_group() as tasks: Loading kilter/service/util.py +13 −0 Original line number Diff line number Diff line Loading @@ -8,8 +8,11 @@ Common helper utilities """ # mypy: disallow-any-explicit=False from __future__ import annotations from collections.abc import Callable from typing import Generic from typing import Optional from typing import TypeVar Loading @@ -17,6 +20,7 @@ from typing import TypeVar import anyio T = TypeVar("T") Fn = TypeVar("Fn", bound=Callable[..., object]) class Broadcast(anyio.Condition, Generic[T]): Loading Loading @@ -94,3 +98,12 @@ class Broadcast(anyio.Condition, Generic[T]): raise self.exc assert self.obj is not None return self.obj def qualname(func: Fn) -> str: """ Return a qualified name for a callable """ if func.__module__ == "__main__": return func.__qualname__ return f"{func.__module__}.{func.__qualname__}" tests/test_runner.py +1 −1 Original line number Diff line number Diff line Loading @@ -309,7 +309,7 @@ class RunnerTests(AsyncTestCase): with self.assertWarns(UserWarning) as wcm: await stream_mock.send_and_expect(Helo("test.example.com"), TemporaryFailure) assert "expected a final response" in str(wcm.warning) assert "expected a valid response" in str(wcm.warning) async def test_macros(self) -> None: """ Loading Loading
.pre-commit-config.yaml +1 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,7 @@ repos: - pydocstyle[toml] - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.961 rev: v0.991 hooks: - id: mypy args: [--follow-imports=silent] Loading
kilter/service/runner.py +8 −2 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ The primary class in this module (`Runner`) is intended to be used with an from __future__ import annotations import logging from collections.abc import AsyncGenerator from warnings import warn Loading @@ -27,6 +28,7 @@ from kilter.protocol.messages import ProtocolFlags from .session import * from .util import Broadcast from .util import qualname MessageChannel = anyio.abc.ObjectStream[Message] Sender = AsyncGenerator[None, Message] Loading Loading @@ -219,9 +221,13 @@ async def _runner( async with session: assert isinstance(session.broadcast, _Broadcast) session.broadcast.task_status = task_status try: final_resp = await fltr(session) except Exception: logging.exception(f"error in filter {qualname(fltr)}") final_resp = TemporaryFailure() if not isinstance(final_resp, _VALID_FINAL_RESPONSES): warn(f"expected a final response from {fltr}, got {final_resp}") warn(f"expected a valid response from {qualname(fltr)}, got {final_resp}") final_resp = TemporaryFailure() async with anyio.create_task_group() as tasks: Loading
kilter/service/util.py +13 −0 Original line number Diff line number Diff line Loading @@ -8,8 +8,11 @@ Common helper utilities """ # mypy: disallow-any-explicit=False from __future__ import annotations from collections.abc import Callable from typing import Generic from typing import Optional from typing import TypeVar Loading @@ -17,6 +20,7 @@ from typing import TypeVar import anyio T = TypeVar("T") Fn = TypeVar("Fn", bound=Callable[..., object]) class Broadcast(anyio.Condition, Generic[T]): Loading Loading @@ -94,3 +98,12 @@ class Broadcast(anyio.Condition, Generic[T]): raise self.exc assert self.obj is not None return self.obj def qualname(func: Fn) -> str: """ Return a qualified name for a callable """ if func.__module__ == "__main__": return func.__qualname__ return f"{func.__module__}.{func.__qualname__}"
tests/test_runner.py +1 −1 Original line number Diff line number Diff line Loading @@ -309,7 +309,7 @@ class RunnerTests(AsyncTestCase): with self.assertWarns(UserWarning) as wcm: await stream_mock.send_and_expect(Helo("test.example.com"), TemporaryFailure) assert "expected a final response" in str(wcm.warning) assert "expected a valid response" in str(wcm.warning) async def test_macros(self) -> None: """ Loading