From 8e127382ade194b30742a62a68fddb71dc7ee412 Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Mon, 7 Oct 2024 14:53:19 -0700 Subject: [PATCH] Ensure that passed kwargs actually are the same as the parameter names instead of compare lengths to avoid false positives when mixing @inject with **kwargs Before it would just check the length of passed arguments vs the signature but that breaks down with **kwarg usage as you can hit cases where the number of passed arguments makes up for the arguments expected to be resolved by inject and then the resolve step is bypassed - leading to exceptions later. --- kink/inject.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kink/inject.py b/kink/inject.py index 552671b..506864d 100644 --- a/kink/inject.py +++ b/kink/inject.py @@ -120,7 +120,7 @@ def _resolve_kwargs(args, kwargs) -> dict: passed_kwargs[parameters_name[key]] = value # prioritise passed kwargs and args resolving - if len(passed_kwargs) == len(parameters_name): + if set(passed_kwargs.keys()) == set(parameters_name): return passed_kwargs resolved_kwargs = _resolve_function_kwargs(binding, parameters_name, parameters, container)