fix: expose() skipped providers inherited from a parent Group - #38
Merged
Conversation
This was referenced Sep 6, 2026
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.
Why
_collect_fixturesdiscovered providers by walkingvars(group)— that iscls.__dict__, the class's own body only. A provider inherited from a parentGroupwas silently skipped, so the fixture set disagreed with the container:The user gets
base_reporegistered and resolvable from the container, but nobase_repofixture, with no error to say so.This was drift, not a decision. The
vars()walk dates to the initial commit(2026-05-24); modern-di added the public
Group.get_named_providers()a monthlater (modern-python/modern-di#242, released in 2.20.0), which returns exactly
the
name -> providermapping this function built by hand, walking the fullMRO. The later seam-adoption pass (589674d) reviewed
resolve_dependencyandadd_providersand adopted the first; it never considered the group walk,though the method already existed. Nothing in
planning/decisions/ordeferred.mdrecords the own-body-only behaviour as intended.Design
_collect_fixturesnow asks each group for its named providers instead ofwalking attributes itself. The cross-group collision check and the
raise-before-returning contract are unchanged. The local skip-non-Provider
branch is gone —
get_named_providers()already filters toAbstractProvider,and name shadowing now follows MRO order, so a child redefining a parent's
provider name yields the child's.
No dependency bump: the floor is already
modern-di>=3,<4, well above the2.20.0 that first shipped the method.
The README's
expose()paragraph — "one pytest fixture per Provider classattribute" — becomes true as written, so it needs no edit.
Compatibility
This can only add fixtures. The one visible edge: a newly-surfaced inherited
name can now collide across groups and raise the existing
ValueError, wherebefore it was invisible.
Non-goals
inject/registerwording in the README and infactory.pybelongs tothe in-flight vocabulary migration on
docs/migrate-off-planning; the errorstring is left byte-identical here so the two do not conflict.
expose()with no groups raisesTypeError. Real but separate; not fixed here.planning/changes/file. By the convention live onmainthis is theLightweight lane and would want one, but
docs/migrate-off-planningdeletesthat directory and is rebased and ready, so adding a file there buys a
guaranteed conflict. The spec is this PR body instead, matching where the repo
is going. Say the word and I'll add the change file.
Verification
just lint-ciclean.just test-ciandjust test-branchpass at 100%line and branch coverage, 17 tests. The new invariant test fails on the old
vars()walk with exactly the three missing inherited names.