Skip to content

feat: add Group.get_named_providers()#242

Merged
lesnik512 merged 5 commits into
mainfrom
feat/group-named-providers
Jun 26, 2026
Merged

feat: add Group.get_named_providers()#242
lesnik512 merged 5 commits into
mainfrom
feat/group-named-providers

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

Adds Group.get_named_providers() -> dict[str, AbstractProvider] — an MRO-walking accessor that maps each declared attribute name to its provider — and reimplements Group.get_providers() as list(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 (notably modern-di-litestar's autowiring) currently reconstruct them with a fragile id()-keyed reverse lookup over group.__dict__. That lookup only sees the subclass __dict__ while get_providers() walks the full MRO, so autowiring a Group that inherits a provider raises KeyError. Exposing names at the source — where Group owns provider declaration and traversal — fixes the bug for every consumer.

The downstream modern-di-litestar change consumes this and is a separate PR, gated on the 2.20.0 release of this package.

Behavior

get_named_providers() preserves the exact semantics of the old get_providers() traversal:

  • MRO order (most-derived first), now pinned by a test
  • first-seen name wins (diamond inheritance returns each provider once)
  • a non-provider override masks the parent provider of the same name

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 passed
  • ruff format / ruff check / ty: clean
  • architecture/providers.md promoted in-PR; just docs-build clean
  • planning bundle added (planning/changes/2026-06-25.04-group-named-providers/); just check-planning OK

After merge

Cut tag 2.20.0 to publish, which unblocks the modern-di-litestar autowiring PR.

@lesnik512 lesnik512 merged commit 1d027a1 into main Jun 26, 2026
7 checks passed
@lesnik512 lesnik512 deleted the feat/group-named-providers branch June 26, 2026 07:44
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant