From 84798fe5eb6861159b5f7c641adbea9660b9668f Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 25 Jun 2026 22:47:58 +0300 Subject: [PATCH] refactor: inline self.context, drop vestigial faststream_context property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 0.7 migration removed the compat branch that once chose between faststream.context and self.context; the faststream_context property was left behind returning self.context unchanged — interface surface for zero behaviour. BaseMiddleware.__init__ assigns self.context from a context: ContextRepo parameter, so ty infers the type directly and the property's explicit annotation buys nothing. Inline self.context.scope(...) at the single call site and delete the property. Behaviour-preserving: consume_scope is exercised on every message by the existing integration round-trips at 100% coverage. Co-Authored-By: Claude Opus 4.8 (1M context) --- modern_di_faststream/main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modern_di_faststream/main.py b/modern_di_faststream/main.py index c0eac32..72c4f82 100644 --- a/modern_di_faststream/main.py +++ b/modern_di_faststream/main.py @@ -41,7 +41,7 @@ async def consume_scope( scope=modern_di.Scope.REQUEST, context={faststream.StreamMessage: msg} ) try: - with self.faststream_context.scope("request_container", request_container): + with self.context.scope("request_container", request_container): return typing.cast( typing.AsyncIterator[DecodedMessage], await call_next(msg), @@ -49,10 +49,6 @@ async def consume_scope( finally: await request_container.close_async() - @property - def faststream_context(self) -> faststream.ContextRepo: - return self.context - def fetch_di_container(app_: faststream.FastStream | AsgiFastStream) -> Container: return typing.cast(Container, app_.context.get("di_container"))