Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderlazarev0 authored Jul 13, 2024
2 parents bbbff18 + eebb26d commit c4ca68a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

- run: pip install smokeshow

- uses: dawidd6/action-download-artifact@v5
- uses: dawidd6/action-download-artifact@v6
with:
workflow: tests.yml
commit: ${{ github.event.workflow_run.head_sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: python -m build

- name: Publish
uses: pypa/gh-action-pypi-publish@v1.8.14
uses: pypa/gh-action-pypi-publish@v1.9.0
with:
password: ${{ secrets.PYPI_API_TOKEN }}

Expand Down
2 changes: 1 addition & 1 deletion fast_depends/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System"""

__version__ = "2.4.4"
__version__ = "2.4.6"
5 changes: 4 additions & 1 deletion fast_depends/core/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def build_call_model(

if dep.cast is True:
class_fields[param_name] = (annotation, ...)

keyword_args.append(param_name)
positional_args.append(param_name)

Expand All @@ -162,8 +163,10 @@ def build_call_model(

if custom.required:
class_fields[param_name] = (annotation, ...)

else:
class_fields[param_name] = (Optional[annotation], None)
class_fields[param_name] = class_fields.get(param_name, (Optional[annotation], None))

keyword_args.append(param_name)

else:
Expand Down
13 changes: 8 additions & 5 deletions fast_depends/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
-r requirements.test.txt

mypy >=1.8.0
ruff ==0.4.8
ruff ==0.5.1
codespell ==2.3.0
17 changes: 17 additions & 0 deletions tests/library/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit c4ca68a

Please sign in to comment.