From 7d972f66fe209155a35b2db737864129f3546114 Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Sat, 2 Nov 2024 11:31:37 +0300 Subject: [PATCH 1/3] Fix typo: supress -> suppress --- stompman/client.py | 9 +++++---- stompman/subscription.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/stompman/client.py b/stompman/client.py index f9c77f51..af90a7e7 100644 --- a/stompman/client.py +++ b/stompman/client.py @@ -1,8 +1,9 @@ import asyncio -from collections.abc import AsyncGenerator, Callable, Coroutine +from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine from contextlib import AsyncExitStack, asynccontextmanager from dataclasses import dataclass, field from functools import partial +import inspect from ssl import SSLContext from types import TracebackType from typing import ClassVar, Literal, Self @@ -30,7 +31,7 @@ class Client: servers: list[ConnectionParameters] = field(kw_only=False) on_error_frame: Callable[[ErrorFrame], None] | None = None - on_heartbeat: Callable[[], None] | None = None + on_heartbeat: Callable[[], None] |Callable[[], Awaitable[None]] | None = None heartbeat: Heartbeat = field(default=Heartbeat(1000, 1000)) ssl: Literal[True] | SSLContext | None = None @@ -144,7 +145,7 @@ async def subscribe( ack: AckMode = "client-individual", headers: dict[str, str] | None = None, on_suppressed_exception: Callable[[Exception, MessageFrame], None], - supressed_exception_classes: tuple[type[Exception], ...] = (Exception,), + suppressed_exception_classes: tuple[type[Exception], ...] = (Exception,), ) -> "Subscription": subscription = Subscription( destination=destination, @@ -152,7 +153,7 @@ async def subscribe( headers=headers, ack=ack, on_suppressed_exception=on_suppressed_exception, - supressed_exception_classes=supressed_exception_classes, + suppressed_exception_classes=suppressed_exception_classes, _connection_manager=self._connection_manager, _active_subscriptions=self._active_subscriptions, ) diff --git a/stompman/subscription.py b/stompman/subscription.py index 5a41639f..c6b3efbc 100644 --- a/stompman/subscription.py +++ b/stompman/subscription.py @@ -24,7 +24,7 @@ class Subscription: handler: Callable[[MessageFrame], Coroutine[None, None, None]] ack: AckMode on_suppressed_exception: Callable[[Exception, MessageFrame], None] - supressed_exception_classes: tuple[type[Exception], ...] + suppressed_exception_classes: tuple[type[Exception], ...] _connection_manager: ConnectionManager _active_subscriptions: ActiveSubscriptions @@ -48,7 +48,7 @@ async def unsubscribe(self) -> None: async def _run_handler(self, *, frame: MessageFrame) -> None: try: await self.handler(frame) - except self.supressed_exception_classes as exception: + except self.suppressed_exception_classes as exception: if self._should_handle_ack_nack and self.id in self._active_subscriptions: await self._connection_manager.maybe_write_frame( NackFrame( From 98292e90ab727e0cb7bd592004c833574ad11c1c Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Sat, 2 Nov 2024 11:33:08 +0300 Subject: [PATCH 2/3] Fix other typos --- stompman/connection.py | 2 +- stompman/transaction.py | 4 ++-- tests/test_subscription.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/stompman/connection.py b/stompman/connection.py index 46f77933..cef86289 100644 --- a/stompman/connection.py +++ b/stompman/connection.py @@ -88,7 +88,7 @@ async def write_frame(self, frame: AnyClientFrame) -> None: async def _read_non_empty_bytes(self, max_chunk_size: int) -> bytes: while ( # noqa: ASYNC110 chunk := await self.reader.read(max_chunk_size) - ) == b"": # pragma: no cover (it defenitely happens) + ) == b"": # pragma: no cover (it definitely happens) await asyncio.sleep(0) return chunk diff --git a/stompman/transaction.py b/stompman/transaction.py index dd7417ef..3a8bd748 100644 --- a/stompman/transaction.py +++ b/stompman/transaction.py @@ -29,8 +29,8 @@ async def __aexit__( await self._connection_manager.maybe_write_frame(AbortFrame(headers={"transaction": self.id})) self._active_transactions.remove(self) else: - commited = await self._connection_manager.maybe_write_frame(CommitFrame(headers={"transaction": self.id})) - if commited: + committed = await self._connection_manager.maybe_write_frame(CommitFrame(headers={"transaction": self.id})) + if committed: self._active_transactions.remove(self) async def send( diff --git a/tests/test_subscription.py b/tests/test_subscription.py index d8fb74ef..0867557a 100644 --- a/tests/test_subscription.py +++ b/tests/test_subscription.py @@ -38,7 +38,7 @@ @pytest.mark.parametrize("ack", get_args(AckMode)) -async def test_client_subscribtions_lifespan_resubscribe(ack: AckMode, faker: faker.Faker) -> None: +async def test_client_subscriptions_lifespan_resubscribe(ack: AckMode, faker: faker.Faker) -> None: connection_class, collected_frames = create_spying_connection(*get_read_frames_with_lifespan([CONNECTED_FRAME], [])) client = EnrichedClient(connection_class=connection_class) sub_destination, message_destination, message_body = faker.pystr(), faker.pystr(), faker.binary(length=10) @@ -78,7 +78,7 @@ async def test_client_subscribtions_lifespan_resubscribe(ack: AckMode, faker: fa ) -async def test_client_subscribtions_lifespan_no_active_subs_in_aexit( +async def test_client_subscriptions_lifespan_no_active_subs_in_aexit( monkeypatch: pytest.MonkeyPatch, faker: faker.Faker ) -> None: monkeypatch.setattr( @@ -109,7 +109,7 @@ async def test_client_subscribtions_lifespan_no_active_subs_in_aexit( @pytest.mark.parametrize("direct_error", [True, False]) -async def test_client_subscribtions_lifespan_with_active_subs_in_aexit( +async def test_client_subscriptions_lifespan_with_active_subs_in_aexit( monkeypatch: pytest.MonkeyPatch, faker: faker.Faker, *, From 0bc2de93374cf28b5be8b6e49f4c45484244398f Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Sat, 2 Nov 2024 11:34:06 +0300 Subject: [PATCH 3/3] Updae --- stompman/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stompman/client.py b/stompman/client.py index af90a7e7..f9f2f904 100644 --- a/stompman/client.py +++ b/stompman/client.py @@ -31,7 +31,7 @@ class Client: servers: list[ConnectionParameters] = field(kw_only=False) on_error_frame: Callable[[ErrorFrame], None] | None = None - on_heartbeat: Callable[[], None] |Callable[[], Awaitable[None]] | None = None + on_heartbeat: Callable[[], None] | None = None heartbeat: Heartbeat = field(default=Heartbeat(1000, 1000)) ssl: Literal[True] | SSLContext | None = None