Skip to content

Commit

Permalink
Try to fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldygg committed Nov 29, 2024
1 parent 797d888 commit b236f2a
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 145 deletions.
2 changes: 1 addition & 1 deletion faststream/broker/fastapi/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class StreamRouter(
def __init__(
self,
*connection_args: Any,
middlewares: Iterable["BrokerMiddleware[MsgType]"] = (),
middlewares: Sequence["BrokerMiddleware[MsgType]"] = (),
prefix: str = "",
tags: Optional[List[Union[str, Enum]]] = None,
dependencies: Optional[Sequence["params.Depends"]] = None,
Expand Down
7 changes: 4 additions & 3 deletions faststream/broker/publisher/fake.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Sequence
from functools import partial
from itertools import chain
from typing import TYPE_CHECKING, Any, Iterable, Optional
Expand All @@ -17,7 +18,7 @@ def __init__(
method: "AsyncFunc",
*,
publish_kwargs: "AnyDict",
middlewares: Iterable["PublisherMiddleware"] = (),
middlewares: Sequence["PublisherMiddleware"] = (),
) -> None:
"""Initialize an object."""
self.method = method
Expand All @@ -29,7 +30,7 @@ async def publish(
message: "SendableMessage",
*,
correlation_id: Optional[str] = None,
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
**kwargs: Any,
) -> Any:
"""Publish a message."""
Expand All @@ -51,7 +52,7 @@ async def request(
/,
*,
correlation_id: Optional[str] = None,
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> Any:
raise NotImplementedError(
"`FakePublisher` can be used only to publish "
Expand Down
10 changes: 5 additions & 5 deletions faststream/broker/publisher/proto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Callable, Generic, Iterable, Optional, Protocol
from typing import TYPE_CHECKING, Any, Callable, Generic, Iterable, Optional, Protocol, Sequence

from typing_extensions import override

Expand Down Expand Up @@ -53,7 +53,7 @@ async def publish(
/,
*,
correlation_id: Optional[str] = None,
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> Optional[Any]:
"""Publishes a message asynchronously."""
...
Expand All @@ -65,7 +65,7 @@ async def request(
/,
*,
correlation_id: Optional[str] = None,
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> Optional[Any]:
"""Publishes a message synchronously."""
...
Expand All @@ -79,8 +79,8 @@ class PublisherProto(
):
schema_: Any

_broker_middlewares: Iterable["BrokerMiddleware[MsgType]"]
_middlewares: Iterable["PublisherMiddleware"]
_broker_middlewares: Sequence["BrokerMiddleware[MsgType]"]
_middlewares: Sequence["PublisherMiddleware"]
_producer: Optional["ProducerProto"]

@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions faststream/broker/publisher/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Iterable,
List,
Optional,
Tuple,
Tuple, Sequence,
)
from unittest.mock import MagicMock

Expand Down Expand Up @@ -49,11 +49,11 @@ def __init__(
self,
*,
broker_middlewares: Annotated[
Iterable["BrokerMiddleware[MsgType]"],
Sequence["BrokerMiddleware[MsgType]"],
Doc("Top-level middlewares to use in direct `.publish` call."),
],
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares."),
],
# AsyncAPI args
Expand Down
4 changes: 2 additions & 2 deletions faststream/broker/subscriber/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ async def process_message(self, msg: MsgType) -> "Response":
result_msg.body,
**result_msg.as_publish_kwargs(),
# publisher middlewares
_extra_middlewares=(
_extra_middlewares=[
m.publish_scope for m in middlewares[::-1]
),
],
)

# Return data for tests
Expand Down
4 changes: 2 additions & 2 deletions faststream/broker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Optional,
Type,
Union,
cast,
cast, Sequence,
)

import anyio
Expand All @@ -37,7 +37,7 @@

async def process_msg(
msg: Optional[MsgType],
middlewares: Iterable["BrokerMiddleware[MsgType]"],
middlewares: Sequence["BrokerMiddleware[MsgType]"],
parser: Callable[[MsgType], Awaitable["StreamMessage[MsgType]"]],
decoder: Callable[["StreamMessage[MsgType]"], "Any"],
) -> Optional["StreamMessage[MsgType]"]:
Expand Down
8 changes: 4 additions & 4 deletions faststream/confluent/broker/registrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -1369,7 +1369,7 @@ def publisher(
],
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -1443,7 +1443,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -1520,7 +1520,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down
18 changes: 9 additions & 9 deletions faststream/confluent/fastapi/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __init__(
Doc("Custom parser object."),
] = None,
middlewares: Annotated[
Iterable[
Sequence[
Union[
"BrokerMiddleware[Message]",
"BrokerMiddleware[Tuple[Message, ...]]",
Expand Down Expand Up @@ -834,7 +834,7 @@ def subscriber(
Doc("Function to decode FastStream msg bytes body to python objects."),
] = None,
middlewares: Annotated[
Iterable["SubscriberMiddleware[KafkaMessage]"],
Sequence["SubscriberMiddleware[KafkaMessage]"],
Doc("Subscriber middlewares to wrap incoming message processing."),
] = (),
filter: Annotated[
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def subscriber(
Doc("Function to decode FastStream msg bytes body to python objects."),
] = None,
middlewares: Annotated[
Iterable["SubscriberMiddleware[KafkaMessage]"],
Sequence["SubscriberMiddleware[KafkaMessage]"],
Doc("Subscriber middlewares to wrap incoming message processing."),
] = (),
filter: Annotated[
Expand Down Expand Up @@ -1630,7 +1630,7 @@ def subscriber(
Doc("Function to decode FastStream msg bytes body to python objects."),
] = None,
middlewares: Annotated[
Iterable["SubscriberMiddleware[KafkaMessage]"],
Sequence["SubscriberMiddleware[KafkaMessage]"],
Doc("Subscriber middlewares to wrap incoming message processing."),
] = (),
filter: Annotated[
Expand Down Expand Up @@ -2038,7 +2038,7 @@ def subscriber(
Doc("Function to decode FastStream msg bytes body to python objects."),
] = None,
middlewares: Annotated[
Iterable["SubscriberMiddleware[KafkaMessage]"],
Sequence["SubscriberMiddleware[KafkaMessage]"],
Doc("Subscriber middlewares to wrap incoming message processing."),
] = (),
filter: Annotated[
Expand Down Expand Up @@ -2306,7 +2306,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -2380,7 +2380,7 @@ def publisher(
],
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -2454,7 +2454,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down Expand Up @@ -2531,7 +2531,7 @@ def publisher(
] = False,
# basic args
middlewares: Annotated[
Iterable["PublisherMiddleware"],
Sequence["PublisherMiddleware"],
Doc("Publisher middlewares to wrap outgoing messages."),
] = (),
# AsyncAPI args
Expand Down
26 changes: 13 additions & 13 deletions faststream/confluent/publisher/asyncapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Tuple,
Union,
cast,
overload,
overload, Sequence,
)

from typing_extensions import override
Expand Down Expand Up @@ -72,8 +72,8 @@ def create(
headers: Optional[Dict[str, str]],
reply_to: str,
# Publisher args
broker_middlewares: Iterable["BrokerMiddleware[ConfluentMsg]"],
middlewares: Iterable["PublisherMiddleware"],
broker_middlewares: Sequence["BrokerMiddleware[ConfluentMsg]"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand All @@ -92,8 +92,8 @@ def create(
headers: Optional[Dict[str, str]],
reply_to: str,
# Publisher args
broker_middlewares: Iterable["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
middlewares: Iterable["PublisherMiddleware"],
broker_middlewares: Sequence["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand All @@ -113,10 +113,10 @@ def create(
reply_to: str,
# Publisher args
broker_middlewares: Union[
Iterable["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
Iterable["BrokerMiddleware[ConfluentMsg]"],
Sequence["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
Sequence["BrokerMiddleware[ConfluentMsg]"],
],
middlewares: Iterable["PublisherMiddleware"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand All @@ -139,10 +139,10 @@ def create(
reply_to: str,
# Publisher args
broker_middlewares: Union[
Iterable["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
Iterable["BrokerMiddleware[ConfluentMsg]"],
Sequence["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
Sequence["BrokerMiddleware[ConfluentMsg]"],
],
middlewares: Iterable["PublisherMiddleware"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand All @@ -162,7 +162,7 @@ def create(
headers=headers,
reply_to=reply_to,
broker_middlewares=cast(
Iterable["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
Sequence["BrokerMiddleware[Tuple[ConfluentMsg, ...]]"],
broker_middlewares,
),
middlewares=middlewares,
Expand All @@ -180,7 +180,7 @@ def create(
headers=headers,
reply_to=reply_to,
broker_middlewares=cast(
Iterable["BrokerMiddleware[ConfluentMsg]"], broker_middlewares
Sequence["BrokerMiddleware[ConfluentMsg]"], broker_middlewares
),
middlewares=middlewares,
schema_=schema_,
Expand Down
18 changes: 9 additions & 9 deletions faststream/confluent/publisher/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Optional,
Tuple,
Union,
cast,
cast, Sequence,
)

from confluent_kafka import Message
Expand Down Expand Up @@ -43,8 +43,8 @@ def __init__(
headers: Optional[Dict[str, str]],
reply_to: Optional[str],
# Publisher args
broker_middlewares: Iterable["BrokerMiddleware[MsgType]"],
middlewares: Iterable["PublisherMiddleware"],
broker_middlewares: Sequence["BrokerMiddleware[MsgType]"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand Down Expand Up @@ -87,7 +87,7 @@ async def request(
correlation_id: Optional[str] = None,
timeout: float = 0.5,
# publisher specific
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> "KafkaMessage":
assert self._producer, NOT_CONNECTED_YET # nosec B101

Expand Down Expand Up @@ -140,8 +140,8 @@ def __init__(
headers: Optional[Dict[str, str]],
reply_to: Optional[str],
# Publisher args
broker_middlewares: Iterable["BrokerMiddleware[Message]"],
middlewares: Iterable["PublisherMiddleware"],
broker_middlewares: Sequence["BrokerMiddleware[Message]"],
middlewares: Sequence["PublisherMiddleware"],
# AsyncAPI args
schema_: Optional[Any],
title_: Optional[str],
Expand Down Expand Up @@ -179,7 +179,7 @@ async def publish(
reply_to: str = "",
no_confirm: bool = False,
# publisher specific
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> Optional[Any]:
assert self._producer, NOT_CONNECTED_YET # nosec B101

Expand Down Expand Up @@ -221,7 +221,7 @@ async def request(
correlation_id: Optional[str] = None,
timeout: float = 0.5,
# publisher specific
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> "KafkaMessage":
return await super().request(
message=message,
Expand Down Expand Up @@ -250,7 +250,7 @@ async def publish(
reply_to: str = "",
no_confirm: bool = False,
# publisher specific
_extra_middlewares: Iterable["PublisherMiddleware"] = (),
_extra_middlewares: Sequence["PublisherMiddleware"] = (),
) -> None:
assert self._producer, NOT_CONNECTED_YET # nosec B101

Expand Down
Loading

0 comments on commit b236f2a

Please sign in to comment.