Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests fail after adding types to test helper function #4

Open
toinbis opened this issue Apr 1, 2024 · 2 comments
Open

tests fail after adding types to test helper function #4

toinbis opened this issue Apr 1, 2024 · 2 comments

Comments

@toinbis
Copy link

toinbis commented Apr 1, 2024

after modifying tests/test_transaction_context.py

from

def add(a, b):
    return a + b

to

def add(a: int, b: int) -> int:
    return a + b

test suite fails:

========================================================== short test summary info ===========================================================
FAILED tests/test_transaction_context.py::test_call_with_dependencies - assert 4 == 3
FAILED tests/test_transaction_context.py::test_call_with_kwarg_and_dependency - assert 22 == 12
======================================================== 2 failed, 43 passed in 0.16s ========================================================

P.S. Thanks a lot for creating and open source'ing python-ddd repo ant lato! Welki dzeki! :)

@pgorecki
Copy link
Owner

pgorecki commented Apr 2, 2024

This problem arises due to the limitations of

def resolve_func_params(

Function arguments are first resolved by type, then by name. After your modification, both a and b have int type, so type resolution (resolve by int and int) takes precedence over name resolution (resolve by a and b), which leads to incorrect values being injected during a function call. For sure this logic could be more sophisticated, but at this point I have no plans for working on it, but please feel free to contribute :)

As a workaround, you can implement your own DependencyProvider that implements your own resolve_func_params and instantiate an app or transaction context with it using

app = Application(dependency_provider=CustomDependencyProvider(...))

@toinbis
Copy link
Author

toinbis commented Apr 2, 2024

Thanks @pgoreck for prompt and clear answeri ! Need to think how I want to approach this :) Kindly please let's keep this issue open for a little bit while. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants