Skip to content

Commit eebb26d

Browse files
authored
fix (#112): correct CustomFields mapping to positional args (#113)
1 parent c190b28 commit eebb26d

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

fast_depends/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System"""
22

3-
__version__ = "2.4.5"
3+
__version__ = "2.4.6"

fast_depends/core/model.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,21 @@ def _solve(
254254
else:
255255
break
256256

257+
keyword_args: Iterable[str]
257258
if has_args := "args" in self.alias_arguments:
258259
kw["args"] = args
259260
keyword_args = self.keyword_args
260261

261262
else:
262-
keyword_args = set(self.keyword_args + self.positional_args)
263-
for arg in keyword_args - set(self.dependencies.keys()):
264-
if args:
265-
kw[arg], args = args[0], args[1:]
266-
else:
263+
keyword_args = self.keyword_args + self.positional_args
264+
265+
for arg in keyword_args:
266+
if not args:
267267
break
268268

269+
if arg not in self.dependencies:
270+
kw[arg], args = args[0], args[1:]
271+
269272
solved_kw: Dict[str, Any]
270273
solved_kw = yield args, kw, call
271274

tests/library/test_custom.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,20 @@ def sync_catch2(key2: HeaderKey) -> float:
183183

184184
assert sync_catch(headers={"key": 1}) == 1
185185
assert sync_catch2(headers={"key2": 1}) == 1
186+
187+
188+
def test_arguments_mapping():
189+
@inject
190+
def func(
191+
d: int = CustomField(cast=False),
192+
b: int = CustomField(cast=False),
193+
c: int = CustomField(cast=False),
194+
a: int = CustomField(cast=False),
195+
):
196+
assert d == 4
197+
assert b == 2
198+
assert c == 3
199+
assert a == 1
200+
201+
for _ in range(50):
202+
func(4, 2, 3, 1)

0 commit comments

Comments
 (0)