feat: context-manager form of Container.override via OverrideHandle (INT-4)#289
Merged
Conversation
…INT-4) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…motion (INT-4) 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.
The accepted INT-4 item from the 2026-07-05 3.0 UX research:
container.override(provider, obj)keeps applying the override immediately and now returns a genericOverrideHandle; used as a context manager,__exit__restores the provider's prior override state — the previously stacked override if there was one, otherwise no override.__enter__returns the override object, sowith container.override(p, mock) as m:binds the mock.override()call and restores it unconditionally on exit — deterministic under nesting (per-handle snapshots; the registry stays a flat dict), on exception, and even ifreset_override()/rootclose_*()ran inside the block. Handles unwind LIFO (with-blocks do this naturally); the docs note manual out-of-order exits can restore stale state.Nonereturn).reset_overrideuntouched; no new exceptions or warnings; zero new lint suppressions.recipes/testing-overrides.mdleads with thewithform as the primary testing spelling;for-fastapi-users.mdmaps it to thedependency_overridestry/finally pattern; the dependency-injector migration mapping is de-drifted;architecture/testing-and-overrides.mdpromoted.just test-ci(100% line coverage, 325 passed),just lint-ci,just docs-build --strict,just check-planning— all green. Adversarial final review probed cached-factory short-circuit order, falsy overrides, child-container handles after close, cross-provider nesting, and close-inside-block — all consistent with the documented semantics.Design bundle (rationale home): planning/changes/2026-07-08.03-override-context-manager.md
🤖 Generated with Claude Code