feat: add block-scoped modifiers#72
Open
invokermain wants to merge 4 commits into
Open
Conversation
Modifiers declared inside a Block now only affect resolutions within that block's scope, matching fx/dig's scoped decorator behavior. Key changes: - Extend _ScopeNode with modifiers field and find_modifier() chain walk - Move global modifiers from Assembler._modifiers onto root _ScopeNode - Fix _bind_arguments to apply modifiers (pre-existing bug where invocations assembled via assemble() received raw values) - Add persistent block scope nodes to Engin, wired as children of root - Route block modifiers to block scope nodes via Modify.apply() - Set block scope context (via _scope_var) for assembly and invocation - Support modifier composition: block modifier receives globally-modified value via instance-level on-stack tracking (not type-level) - Cache modified values on modifier's source node to prevent leaking across scopes Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
- Coverage 91.29% 90.72% -0.57%
==========================================
Files 19 19
Lines 1309 1402 +93
Branches 184 201 +17
==========================================
+ Hits 1195 1272 +77
- Misses 69 83 +14
- Partials 45 47 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- modifiers.md: document block scoping behavior, composition with global modifiers, and update "one modifier per type" to "per type per scope" - blocks.md: add tip about block-scoped modifier behavior - CHANGELOG.md: remove outdated "global only" caveat from v0.4.0 entry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Block scope nodes now mirror the block nesting hierarchy. When OuterBlock includes InnerBlock as an option, InnerBlock's scope node is parented to OuterBlock's node (not root). This means inner block invocations see outer block modifiers via the scope chain walk, matching dig's nested scope behavior. Co-Authored-By: Claude Opus 4.6 <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.
Summary
Modifydeclared inside aBlocknow only affects resolutions within that block's scope, matching fx/dig's scoped decorator behavior. Modifiers in BlockA don't leak to BlockB or top-level invocations."GLOBAL_FOO")._bind_arguments(used byassemble()) now applies modifiers. Previously, invocations assembled viaassemble()received raw provider values, bypassing all modifiers.Implementation details
_ScopeNodeextended withmodifiersdict andfind_modifier()chain walk (mirrors dig'sstoresToRoot())Assembler._modifiersontoroot_node.modifiers_ScopeNodeinstances parented to root, created duringBlock.apply()Engin.run()sets_scope_varto the block's node when assembling/invoking block invocationsset[int]of modifier IDs) replaces type-level tracking to allow modifier composition across scope levelsfind_modified()stops at nodes owning a modifier for the type, preventing inheritance of parent's cached modified valueTest plan
Assembler.build)poe checkpasses (ruff format, ruff lint, mypy)🤖 Generated with Claude Code