Skip to content

Commit

Permalink
lint: fix rabbit response types
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Dec 15, 2024
1 parent c7f4bc3 commit 195035e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
8 changes: 0 additions & 8 deletions faststream/_internal/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing_extensions import (
ParamSpec,
TypeAlias,
TypeVar as TypeVar313,
)

from faststream._internal.basic_types import AsyncFuncAny
Expand Down Expand Up @@ -85,13 +84,6 @@ def __call__(
]


PublishCommandType = TypeVar313(
"PublishCommandType",
bound=PublishCommand,
default=PublishCommand,
)


class PublisherMiddleware(Protocol):
"""Publisher middleware interface."""

Expand Down
14 changes: 12 additions & 2 deletions faststream/middlewares/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from collections.abc import Awaitable
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional

from typing_extensions import Self
from typing_extensions import (
Self,
TypeVar as TypeVar313,
)

from faststream._internal.types import PublishCommandType
from faststream.response import PublishCommand

if TYPE_CHECKING:
from types import TracebackType
Expand All @@ -13,6 +16,13 @@
from faststream.message import StreamMessage


PublishCommandType = TypeVar313(
"PublishCommandType",
bound=PublishCommand,
default=PublishCommand,
)


class BaseMiddleware(Generic[PublishCommandType]):
"""A base middleware class."""

Expand Down
3 changes: 1 addition & 2 deletions faststream/opentelemetry/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from opentelemetry.trace import Link, Span
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator

from faststream._internal.types import PublishCommandType
from faststream.middlewares.base import BaseMiddleware
from faststream.middlewares.base import BaseMiddleware, PublishCommandType
from faststream.opentelemetry.baggage import Baggage
from faststream.opentelemetry.consts import (
ERROR_TYPE,
Expand Down
3 changes: 1 addition & 2 deletions faststream/prometheus/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
from typing import TYPE_CHECKING, Any, Callable, Generic, Optional

from faststream._internal.constants import EMPTY
from faststream._internal.types import PublishCommandType
from faststream.exceptions import IgnoredException
from faststream.message import SourceType
from faststream.middlewares.base import BaseMiddleware
from faststream.middlewares.base import BaseMiddleware, PublishCommandType
from faststream.prometheus.consts import (
PROCESSING_STATUS_BY_ACK_STATUS,
PROCESSING_STATUS_BY_HANDLER_EXCEPTION_MAP,
Expand Down
15 changes: 11 additions & 4 deletions faststream/rabbit/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
from faststream.response.publish_type import PublishType

if TYPE_CHECKING:
from typing import TypedDict

from aio_pika.abc import TimeoutType

from faststream.rabbit.publisher.options import MessageOptions
from faststream.rabbit.types import AioPikaSendableMessage

class _PublishOptions(TypedDict):
timeout: TimeoutType
mandatory: bool
immediate: bool


class RabbitResponse(Response):
def __init__(
Expand All @@ -33,15 +40,15 @@ def __init__(
)

self.message_options = message_options
self.publish_options = {
self.publish_options: _PublishOptions = {
"mandatory": mandatory,
"immediate": immediate,
"timeout": timeout,
}

@override
def as_publish_command(self) -> "RabbitPublishCommand":
return RabbitPublishCommand(
return RabbitPublishCommand( # type: ignore[misc]
message=self.body,
headers=self.headers,
correlation_id=self.correlation_id,
Expand All @@ -65,11 +72,11 @@ def __init__(
mandatory: bool = True,
immediate: bool = False,
timeout: "TimeoutType" = None,
correlation_id: Optional[str] = None,
**message_options: Unpack["MessageOptions"],
) -> None:
headers = message_options.pop("headers", {})
reply_to = message_options.pop("reply_to", "")
reply_to = message_options.pop("reply_to") or ""
correlation_id = message_options.pop("correlation_id", None)

super().__init__(
body=message,
Expand Down
2 changes: 1 addition & 1 deletion faststream/rabbit/schemas/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ def _setup(
self.virtual_host = virtual_host

# Setup next parent class
super()._setup(**kwargs)
super()._setup(**kwargs) # type: ignore[misc]

0 comments on commit 195035e

Please sign in to comment.