Repository navigation
Extend parent injector multibindings in child injectors - #324
DYNOSuprovo wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #324 +/- ##
==========================================
+ Coverage 96.83% 96.89% +0.05%
==========================================
Files 1 1
Lines 601 612 +11
Branches 103 94 -9
==========================================
+ Hits 582 593 +11
Misses 13 13
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for your contribution! I think this is something Injector should support. I'll just think one round about the implementation. |
|
If you're able to, please fix CI with a bit more coverage, and resolve the conflicts (sorry!). |
|
Thanks for the review and feedback @davidparsson! Glad to hear this aligns with Injector's goals. I will resolve the merge conflicts and add more test cases to increase CI coverage. |
Allow child injectors to inherit and extend multibindings registered on their parent injectors for both sequence and mapping multibinds. Fixes python-injector#297 Signed-off-by: DYNOSuprovo <DYNOSuprovo@users.noreply.github.com>
cd58440 to
8e6f24b
Compare
|
Rebased cleanly onto latest \master, resolved the conflict in \CHANGES, and added test coverage for edge cases (including child multibinds when the parent has no binding for that interface, and child multibinds when the parent has a non-multibinder binding). All 140 tests pass with full 100% branch and statement coverage on the new lines. |
There was a problem hiding this comment.
🟡 Changes recommended
Inherited scoped-provider errors can be swallowed, silently returning incomplete collections.
1 open finding
What changed in this PR
Extends inherited multibindings in child injectors, addressing #297 while preserving parent isolation.
Changes:
- Combines parent and child contributions, with parent-first lists and child-overridden dictionary entries.
- Adds hierarchy and fallback tests.
- Documents the behavior change.
| File | Description |
|---|---|
| injector/__init__.py | Resolves inherited multibinding providers before local providers. |
| injector_test.py | Tests inheritance, overrides, skipped levels, and fallback behavior. |
| CHANGES | Announces inherited multibinding support. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| try: | ||
| parent_binding, _ = self._owner_binder.parent._get_binding(self._interface) | ||
| if isinstance(parent_binding.provider, MultiBinder): | ||
| yield from parent_binding.provider.get_scoped_providers(injector) | ||
| except KeyError: | ||
| pass |

Summary
Fixes #297.
Previously, when a child injector configured multibindings on an interface (such as
List[T]orDict[K, V]), a newMultiBinderwas instantiated without reference to the parent injector's multibinder. Consequently,child_injector.get()only retrieved the multibindings defined on the child, completely shadowing the parent's multibindings.This change:
BinderandinterfaceonMultiBinder.MultiBinder.get_scoped_providers(), checks if the owner binder has a parent binder with a registeredMultiBinderfor the same interface, yielding scoped providers from the parent first before yielding child providers.Tests
Added test cases in
injector_test.py:test_multibinds_are_extended_by_child_injectorstest_multibind_dict_is_extended_by_child_injectorstest_multibind_multi_level_hierarchy_extended_by_child_injectorstest_multibind_skipped_level_child_injector