refactor: name the container context keys#19
Merged
Conversation
The root and per-message containers are handed off through FastStream's ContextRepo under bare string keys, each written in one place and read in another: "di_container" setup_di (write) -> fetch_di_container (read) "request_container" _DiMiddleware.consume_scope (write) -> Dependency (read) Writer and reader had to agree on the literal with nothing enforcing it; a rename or typo on either end failed only at runtime. Promote both to module-level constants (_ROOT_CONTAINER_KEY, _REQUEST_CONTAINER_KEY) so the handoff has one definition and a mismatch is a NameError at import. Values unchanged; behaviour-preserving. Existing integration round-trips cover every site at 100%. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replace the four bare
ContextRepostring literals with two module-level constants:Why
The root and per-message containers are handed off through FastStream's
ContextRepounder string keys — each written in one place, read in another:"di_container"setup_difetch_di_container"request_container"_DiMiddleware.consume_scopeDependency.__call__Writer and reader had to agree on the literal with nothing enforcing it — this handoff is a seam, but an invisible one carried by duplicated strings. A rename or typo on either end failed silently at runtime, not at lint/type-check time. Naming the keys gives the seam one definition: writer and reader provably reference the same name, and a mismatch is a
NameErrorat import.This is a locality win, not new behaviour. Values are unchanged.
Verification
just lintclean (ruff format + ruff check + ty).just test— 5 passed,main.pyat 100% coverage. Every key site is exercised by the existing NATS integration round-trips, so no new test is needed.🤖 Generated with Claude Code