From 9da3bc6815a683e8ea6351dda3a807a09954449d Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Tue, 5 Nov 2024 09:30:20 +0300 Subject: [PATCH] Change required return type in callbacks from `None` to `Any` --- stompman/client.py | 12 ++++++------ stompman/connection_lifespan.py | 4 ++-- stompman/subscription.py | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/stompman/client.py b/stompman/client.py index 0e238332..ec06c44c 100644 --- a/stompman/client.py +++ b/stompman/client.py @@ -1,12 +1,12 @@ import asyncio import inspect -from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine +from collections.abc import AsyncGenerator, Awaitable, Callable from contextlib import AsyncExitStack, asynccontextmanager from dataclasses import dataclass, field from functools import partial from ssl import SSLContext from types import TracebackType -from typing import ClassVar, Literal, Self +from typing import Any, ClassVar, Literal, Self from stompman.config import ConnectionParameters, Heartbeat from stompman.connection import AbstractConnection, Connection @@ -30,8 +30,8 @@ class Client: PROTOCOL_VERSION: ClassVar = "1.2" # https://stomp.github.io/stomp-specification-1.2.html 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_error_frame: Callable[[ErrorFrame], Any] | None = None + on_heartbeat: Callable[[], Any] | Callable[[], Awaitable[Any]] | None = None heartbeat: Heartbeat = field(default=Heartbeat(1000, 1000)) ssl: Literal[True] | SSLContext | None = None @@ -146,11 +146,11 @@ async def begin(self) -> AsyncGenerator[Transaction, None]: async def subscribe( self, destination: str, - handler: Callable[[MessageFrame], Coroutine[None, None, None]], + handler: Callable[[MessageFrame], Awaitable[Any]], *, ack: AckMode = "client-individual", headers: dict[str, str] | None = None, - on_suppressed_exception: Callable[[Exception, MessageFrame], None], + on_suppressed_exception: Callable[[Exception, MessageFrame], Any], suppressed_exception_classes: tuple[type[Exception], ...] = (Exception,), ) -> "Subscription": subscription = Subscription( diff --git a/stompman/connection_lifespan.py b/stompman/connection_lifespan.py index 31013ed2..8d2fdb7c 100644 --- a/stompman/connection_lifespan.py +++ b/stompman/connection_lifespan.py @@ -2,7 +2,7 @@ from collections.abc import Callable from contextlib import suppress from dataclasses import dataclass -from typing import Protocol +from typing import Any, Protocol from uuid import uuid4 from stompman.config import ConnectionParameters, Heartbeat @@ -37,7 +37,7 @@ class ConnectionLifespan(AbstractConnectionLifespan): disconnect_confirmation_timeout: int active_subscriptions: ActiveSubscriptions active_transactions: ActiveTransactions - set_heartbeat_interval: Callable[[float], None] + set_heartbeat_interval: Callable[[float], Any] async def _establish_connection(self) -> StompProtocolConnectionIssue | None: await self.connection.write_frame( diff --git a/stompman/subscription.py b/stompman/subscription.py index c6b3efbc..4d826cdf 100644 --- a/stompman/subscription.py +++ b/stompman/subscription.py @@ -1,5 +1,6 @@ -from collections.abc import Callable, Coroutine +from collections.abc import Awaitable, Callable from dataclasses import dataclass, field +from typing import Any from uuid import uuid4 from stompman.connection import AbstractConnection @@ -21,9 +22,9 @@ class Subscription: id: str = field(default_factory=lambda: _make_subscription_id(), init=False) # noqa: PLW0108 destination: str headers: dict[str, str] | None - handler: Callable[[MessageFrame], Coroutine[None, None, None]] + handler: Callable[[MessageFrame], Awaitable[Any]] ack: AckMode - on_suppressed_exception: Callable[[Exception, MessageFrame], None] + on_suppressed_exception: Callable[[Exception, MessageFrame], Any] suppressed_exception_classes: tuple[type[Exception], ...] _connection_manager: ConnectionManager _active_subscriptions: ActiveSubscriptions