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

Overridden arguments not considered #98

Open
reritom opened this issue Jun 4, 2024 · 1 comment
Open

Overridden arguments not considered #98

reritom opened this issue Jun 4, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@reritom
Copy link

reritom commented Jun 4, 2024

Perhaps related to the comment on here about the library not being a real dependency injection system #65

Using version 2.4.3

When passing an explicit argument for a parameter defined as a dependency, I would expect the explicit argument to be used and the dependency to be overridden/ignored, but it doesn't seem to be the case.

from fast_depends import inject, Depends

def my_dependency():
    return "foo"

@inject
def my_function(dep = Depends(my_dependency)):
    print(dep)

my_function()
# foo

my_function(dep="bar")
# foo
@Lancetnik Lancetnik added the bug Something isn't working label Jun 5, 2024
alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 9, 2024
alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 9, 2024
@alexanderlazarev0
Copy link

alexanderlazarev0 commented Jul 9, 2024

The reason this doesn't work seems to be due to the fact that this is supported:

def test_class_depends():
    class MyDep:
        def __init__(self, a: int):
            self.a = a

    @inject
    def some_func(a=Depends(MyDep)):
        assert isinstance(a, MyDep)
        assert a.a == 3
        return a

    some_func(3)

Ref

So also this works:

from fast_depends import Depends, inject

def my_dep(a: int):
    return a + 5

@inject
def some_func(a=Depends(my_dep)):
    return a

some_func(3) # 8

alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 9, 2024
alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 9, 2024
alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 13, 2024
alexanderlazarev0 pushed a commit to alexanderlazarev0/FastDepends that referenced this issue Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants