Skip to content

Commit 00326e9

Browse files
fix: type propogation through provided (#733)
Co-authored-by: Gonzalo Martinez <gonzarmv@gmail.com>
1 parent 46646b1 commit 00326e9

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

src/dependency_injector/providers.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Provider(Generic[T]):
6969
@property
7070
def provider(self) -> Provider: ...
7171
@property
72-
def provided(self) -> ProvidedInstance: ...
72+
def provided(self) -> ProvidedInstance[T]: ...
7373
def enable_async_mode(self) -> None: ...
7474
def disable_async_mode(self) -> None: ...
7575
def reset_async_mode(self) -> None: ...

tests/typing/callable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def create(cls) -> Animal:
3434

3535
# Test 5: to check the provided instance interface
3636
provider5 = providers.Callable(Animal)
37-
provided5: providers.ProvidedInstance = provider5.provided
37+
provided5: Animal = provider5.provided()
3838
attr_getter5: providers.AttributeGetter = provider5.provided.attr
3939
item_getter5: providers.ItemGetter = provider5.provided["item"]
4040
method_caller: providers.MethodCaller = provider5.provided.method.call(123, arg=324)

tests/typing/dict.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
a1=providers.Factory(object),
3535
a2=providers.Factory(object),
3636
)
37-
provided5: providers.ProvidedInstance = provider5.provided
37+
provided5: dict[Any, Any] = provider5.provided()
3838

3939

4040
# Test 6: to check the return type with await

tests/typing/factory.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create(cls) -> Animal:
3737

3838
# Test 5: to check the provided instance interface
3939
provider5 = providers.Factory(Animal)
40-
provided5: providers.ProvidedInstance = provider5.provided
40+
provided5: Animal = provider5.provided()
4141
attr_getter5: providers.AttributeGetter = provider5.provided.attr
4242
item_getter5: providers.ItemGetter = provider5.provided["item"]
4343
method_caller5: providers.MethodCaller = provider5.provided.method.call(123, arg=324)

tests/typing/list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
providers.Factory(object),
2424
providers.Factory(object),
2525
)
26-
provided3: providers.ProvidedInstance = provider3.provided
26+
provided3: List[Any] = provider3.provided()
2727
attr_getter3: providers.AttributeGetter = provider3.provided.attr
2828
item_getter3: providers.ItemGetter = provider3.provided["item"]
2929
method_caller3: providers.MethodCaller = provider3.provided.method.call(123, arg=324)

tests/typing/object.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Test 2: to check the provided instance interface
1111
provider2 = providers.Object(int)
12-
provided2: providers.ProvidedInstance = provider2.provided
12+
provided2: Type[int] = provider2.provided()
1313
attr_getter2: providers.AttributeGetter = provider2.provided.attr
1414
item_getter2: providers.ItemGetter = provider2.provided["item"]
1515
method_caller2: providers.MethodCaller = provider2.provided.method.call(123, arg=324)

tests/typing/provider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Test 1: to check .provided attribute
55
provider1: providers.Provider[int] = providers.Object(1)
6-
provided: providers.ProvidedInstance = provider1.provided
6+
provided: int = provider1.provided()
77

88
# Test 2: to check async mode API
99
provider2: providers.Provider = providers.Provider()

tests/typing/singleton.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def create(cls) -> Animal:
3737

3838
# Test 5: to check the provided instance interface
3939
provider5 = providers.Singleton(Animal)
40-
provided5: providers.ProvidedInstance = provider5.provided
40+
provided5: Animal = provider5.provided()
4141
attr_getter5: providers.AttributeGetter = provider5.provided.attr
4242
item_getter5: providers.ItemGetter = provider5.provided["item"]
4343
method_caller5: providers.MethodCaller = provider5.provided.method.call(123, arg=324)

0 commit comments

Comments
 (0)