kodemore / kink

Dependency injection container made for Python
MIT License
397 stars 25 forks source link

Unexpected resolution for passed parameters #64

Open aikidojohn opened 3 weeks ago

aikidojohn commented 3 weeks ago

When some, but not all, parameters are passed to a kink wrapped function, all parameters are resolved. This includes the passed parameters. This unexpected resolution can lead to unexpected behaviors and errors.

I ran into this while integrating Kink into a complex codebase. The codebase already has a large test suite that I didn't intend to update right away. Unfortunately there were some errors caused by the way Kink handles passed parameters.

We have many classes that take in some constructor arguments and have others defaulted. The tests would often not pass in the defaulted parameters - only the required ones. So in a case like this, the required parameters are mocked and passed in, but since len(passed_parameters) != len(constructor_parmeters), kink does parameter resolution for ALL parameters including passed parameters. This caused errors and unexpected behavior in the test suite since some of the objects being constructed are poorly behaved and have side-effects on construction (not ideal, but a real world situation).

I have provided a potential fix here: https://github.com/kodemore/kink/pull/63