From 2c7a01b28d5eeffe17a0732efc4f7ddc2030b628 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 4 Jun 2026 10:02:47 +0300 Subject: [PATCH] chore: migrate to faststream 0.7 (drop <0.7 support) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the dependency from "faststream>=0.5,<0.7" to "faststream>=0.7,<0.8". Drops the _OLD_MIDDLEWARES runtime version-sniff entirely — single code path, no compat shim, no <0.7 support. The package's version="0" pre-release posture allows the hard break. Changes: - pyproject.toml: pin "faststream>=0.7,<0.8". - modern_di_faststream/main.py: - Remove "from importlib.metadata import version". - Remove _OLD_MIDDLEWARES sniff and its <0.6 branch in _DiMiddleware.faststream_context. - Collapse the if/else property pair into a single property returning self.context. Companion to: planning/specs/2026-06-04-faststream-0.7-migration-design.md planning/plans/2026-06-04-faststream-0.7-migration-pr2-plan.md Co-Authored-By: Claude Opus 4.7 (1M context) --- modern_di_faststream/main.py | 19 +++---------------- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/modern_di_faststream/main.py b/modern_di_faststream/main.py index a6ad2a9..017d827 100644 --- a/modern_di_faststream/main.py +++ b/modern_di_faststream/main.py @@ -1,7 +1,6 @@ import dataclasses import typing from collections.abc import Awaitable, Callable -from importlib.metadata import version import faststream import modern_di @@ -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",) @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 2e099e4..87ca9ee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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]