diff --git a/fast_depends/__about__.py b/fast_depends/__about__.py index 1064c1f..412d0f4 100644 --- a/fast_depends/__about__.py +++ b/fast_depends/__about__.py @@ -1,3 +1,3 @@ """FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System""" -__version__ = "2.4.5" +__version__ = "2.4.6" diff --git a/fast_depends/core/model.py b/fast_depends/core/model.py index 3403351..4ed3391 100644 --- a/fast_depends/core/model.py +++ b/fast_depends/core/model.py @@ -254,18 +254,21 @@ def _solve( else: break + keyword_args: Iterable[str] if has_args := "args" in self.alias_arguments: kw["args"] = args keyword_args = self.keyword_args else: - keyword_args = set(self.keyword_args + self.positional_args) - for arg in keyword_args - set(self.dependencies.keys()): - if args: - kw[arg], args = args[0], args[1:] - else: + keyword_args = self.keyword_args + self.positional_args + + for arg in keyword_args: + if not args: break + if arg not in self.dependencies: + kw[arg], args = args[0], args[1:] + solved_kw: Dict[str, Any] solved_kw = yield args, kw, call diff --git a/tests/library/test_custom.py b/tests/library/test_custom.py index 4044df9..1cefc6d 100644 --- a/tests/library/test_custom.py +++ b/tests/library/test_custom.py @@ -183,3 +183,20 @@ def sync_catch2(key2: HeaderKey) -> float: assert sync_catch(headers={"key": 1}) == 1 assert sync_catch2(headers={"key2": 1}) == 1 + + +def test_arguments_mapping(): + @inject + def func( + d: int = CustomField(cast=False), + b: int = CustomField(cast=False), + c: int = CustomField(cast=False), + a: int = CustomField(cast=False), + ): + assert d == 4 + assert b == 2 + assert c == 3 + assert a == 1 + + for _ in range(50): + func(4, 2, 3, 1)