FastDepends
FastDepends copied to clipboard
Overridden arguments not considered
Perhaps related to the comment on here about the library not being a real dependency injection system https://github.com/Lancetnik/FastDepends/issues/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
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)
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
Seems working fine in 3.0.0 Please, reopen the Issue if the problem still exist