feat: add Group.get_named_providers()#242
Merged
Merged
Conversation
This was referenced Jun 26, 2026
lesnik512
added a commit
that referenced
this pull request
Jun 26, 2026
Curated notes for the 2.21.0 stable tag — release.yml requires planning/releases/<tag>.md before it will publish. 2.20.0 already shipped get_named_providers (#242) without context_type (#244), so the public context_type attribute ships as 2.21.0. 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
Adds
Group.get_named_providers() -> dict[str, AbstractProvider]— an MRO-walking accessor that maps each declared attribute name to its provider — and reimplementsGroup.get_providers()aslist(cls.get_named_providers().values()), so the traversal and dedup/masking logic lives in one place.Why
get_providers()discards the attribute name each provider was declared under. Downstream integrations that need names (notablymodern-di-litestar's autowiring) currently reconstruct them with a fragileid()-keyed reverse lookup overgroup.__dict__. That lookup only sees the subclass__dict__whileget_providers()walks the full MRO, so autowiring aGroupthat inherits a provider raisesKeyError. Exposing names at the source — whereGroupowns provider declaration and traversal — fixes the bug for every consumer.The downstream
modern-di-litestarchange consumes this and is a separate PR, gated on the2.20.0release of this package.Behavior
get_named_providers()preserves the exact semantics of the oldget_providers()traversal:get_providers()'s contract (return type, order, dedup, masking) is unchanged — proven by the pre-existing tests plus a consistency test.Tests / checks
just test-ci: 100% line coverage, 236 passedruff format/ruff check/ty: cleanarchitecture/providers.mdpromoted in-PR;just docs-buildcleanplanning/changes/2026-06-25.04-group-named-providers/);just check-planningOKAfter merge
Cut tag
2.20.0to publish, which unblocks themodern-di-litestarautowiring PR.