Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions modern_di_faststream/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
import typing
from collections.abc import Awaitable, Callable
from importlib.metadata import version

import faststream
import modern_di
Expand All @@ -17,10 +16,6 @@
faststream_message_provider = providers.ContextProvider(scope=Scope.REQUEST, context_type=faststream.StreamMessage)


_major, _minor, *_ = version("faststream").split(".")
_OLD_MIDDLEWARES = int(_major) == 0 and int(_minor) < 6 # noqa: PLR2004


class _DIMiddlewareFactory:
__slots__ = ("di_container",)

Expand Down Expand Up @@ -53,17 +48,9 @@ async def consume_scope(
finally:
await request_container.close_async()

if _OLD_MIDDLEWARES: # pragma: no cover

@property
def faststream_context(self) -> faststream.ContextRepo:
return typing.cast(faststream.ContextRepo, faststream.context) # ty: ignore[possibly-missing-submodule]

else:

@property
def faststream_context(self) -> faststream.ContextRepo:
return self.context
@property
def faststream_context(self) -> faststream.ContextRepo:
return self.context


def fetch_di_container(app_: faststream.FastStream | AsgiFastStream) -> Container:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ classifiers = [
"Typing :: Typed",
"Topic :: Software Development :: Libraries",
]
dependencies = ["faststream>=0.5,<0.7", "modern-di>=2,<3"]
dependencies = ["faststream>=0.7,<0.8", "modern-di>=2,<3"]
version = "0"

[project.urls]
Expand Down
Loading