Repository navigation
fix(di): skip auto-wiring unregistered constructor parameters with default values - #134
Conversation
|
Hi @dwaddle, First off, thank you so much for this! The PR is super clean and the unit tests you added are spot-on. The CI test suite ran across 518 tests (516 passed 🎉), but caught two minor regressions on existing lifecycle edge-cases:
If you have a few minutes to tweak the auto-wiring logic to let these pass, that would be amazing! No pressure at all though—if you're short on time, just let me know and I'd be more than happy to push a commit to your branch to patch these two tests and get it merged for v0.1.0-rc.3. Really appreciate your support for ZCore! 🚀 |
…ependencies outside active scope
|
Hi @alialfostovar, thank you for the kind words and for pointing out those two lifecycle edge-cases! I've pushed
Verified locally across the full suite (519/519 passing). |
|
Hi @dwaddle, Fantastic turnaround! Thank you for addressing both of those lifecycle edge cases so cleanly—and awesome to see all 519 tests green across the board 🎉 I'll do a final review pass on the full diff shortly and merge this into master for the upcoming Really appreciate your quality contribution! 🚀 |
Fixes #131
Problem
IoCContainer._auto_wirecollected all type-annotated constructor parameters intodependencieswithout checking whetherparam.default is not inspect.Parameter.empty. When a class constructor declared parameters with default values for primitive or unregistered types (e.g.,timeout: int = 30orclient: Any = None),_auto_wireattempted to resolve those types through the container, raisingTypeErroror unexpected resolution failures.Solution
IoCContainer._is_registeredto check whether a dependency type is explicitly registered in_singletons,_scoped_definitions,_factories, or active_scoped_instances.IoCContainer._auto_wire, skip variadic parameters (*args,**kwargs) and parameters that define a default value (param.default is not inspect.Parameter.empty) when their type annotation is not explicitly registered in the container, allowing Python to fall back to the parameter's default value (consistent withbackground_task._resolve_injections).tests/test_di.pycovering primitive/unregistered defaults, mixed required dependencies + defaults, and explicitly registered dependencies with defaults.Backward Compatibility
100% backward compatible; all required constructor dependencies and explicitly registered optional dependencies continue to be injected identically.