Conversation
|
@aikidojohn Thanks for your contribution. |
| raise Exception("Constructing expensive object") | ||
|
|
||
| @inject | ||
| def greet(namer: ExpensiveObject, greeting: str = "Hello %s") -> str: |
There was a problem hiding this comment.
@aikidojohn, the fact that this works in such scenarios is a side effect I allowed in the initial design, but it was not my intention for the library to be used in this way. I find it concerning when functions are called without parameters, despite their signature indicating otherwise.
|
@aikidojohn |
|
@dkraczkowski Am I understanding your response correctly that it is expected behavior that the only way to override DI when calling a function is to pass ALL of the function arguments, even if some have defaults? |
When parameters are partially specified by the caller, parameter resolution happens for all parameters, including the passed in parameters. This can cause some unexpected behavior if the construction of the parameter is expensive or has side-effects.
I ran into this issue when introducing Kink into a complex project with a large unit test suit. The unit tests would pass in mock objects, but Kink would try to resolve them anyway, sometimes resulting in unexpected side-effects and errors.
This change will skip parameter resolution for parameters that were passed in by the caller.
** Maintainers - I am new to the Kink codebase. If there is a better way/place to make this change, I am happy to take feedback and see this change through.