refactor: extract _collect_fixtures seam from expose#13
Merged
Conversation
Split expose() into a pure decision and a thin installer. The new private _collect_fixtures(*groups) walks the groups, skips non-Providers, detects cross-group name collisions, and returns a name->provider mapping. expose() now resolves that mapping (surfacing any error) before touching the module, then installs via modern_di_fixture. Guarantee added: collision is atomic. The ValueError is raised before any setattr, so a failed expose() leaves the target module untouched. The decision is now testable through a return value instead of module side effects, so the skip/collision/no-groups tests move to a new pure file and the four test_expose_* files collapse to three. Public surface unchanged (still two public symbols); error messages verbatim; 100% coverage holds. 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
Splits
expose()into a pure decision and a thin installer.A new private
_collect_fixtures(*groups) -> dict[str, AbstractProvider]walks the groups, skips non-Provider attributes, detects cross-group name collisions, and returns aname -> providermapping.expose()now resolves that mapping (surfacing any error) before touching the module, then installs each provider via the existingmodern_di_fixture.Why
expose()fused three jobs behind one side-effecting interface — discovery, collision detection, andsetattr-onto-module. The testable core ("which names, any conflicts?") was only observable past the interface, so the tests had to build throwaway modules and probe withhasattr. And because installation mutates module globals, two configurations couldn't share a module — which is exactly why the suite had four near-identicaltest_expose_*.pyfiles.Drawing the seam at the decision makes that core a value you can assert on directly.
Behaviour change: atomic collision
The
ValueErroris now raised before anysetattr, so a failedexpose()leaves the target module untouched (previously the first group's fixtures were already installed when the collision fired). Locked in with a test.Tests: 4 → 3 expose files
test_collect_fixtures.py(new) — skip / collision / no-groups / mapping rules tested directly against the seam's return value. No throwaway modules, nohasattrprobing.test_expose.py— integration only: app-scope resolution, multiple groups (folded in), themodule=seam, theexecRuntimeError, and the new atomicity guarantee.test_expose_request_scope.py— kept separate, with a comment explaining therequest_widgetname collision that forces it.test_modern_di_fixture.py— untouched.Contract
_collect_fixturesis private.just lint(ruff + ty) clean;just test-cigreen at 100% coverage.🤖 Generated with Claude Code