Skip to content

Commit 029d8a9

Browse files
committed
fix: add test dep_obj type hint
1 parent e1eb825 commit 029d8a9

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

tests/test_graph.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import asyncio
22
import uuid
3-
from typing import Any, AsyncGenerator, Generator, Generic, TypeVar
3+
from typing import Any, AsyncGenerator, Generator, Generic, TypeVar, Tuple
44

55
import pytest
66

@@ -571,3 +571,41 @@ def target(my_dep: GenericClass[int] = Depends(func_dep)) -> int:
571571
result = target(**g.resolve_kwargs())
572572

573573
assert result == 123
574+
575+
576+
@pytest.mark.anyio
577+
async def test_graph_type_hints() -> None:
578+
def dep() -> int:
579+
return 123
580+
581+
def target(class_val: int = Depends(dep, use_cache=False)) -> None:
582+
return None
583+
584+
g = DependencyGraph(target=target)
585+
for dep_obj in g.subgraphs.keys():
586+
assert dep_obj.param_name == "class_val"
587+
assert dep_obj.dependency == dep
588+
assert dep_obj.signature.name == "class_val"
589+
assert dep_obj.signature.annotation == int
590+
591+
592+
@pytest.mark.anyio
593+
async def test_graph_generic_type_hints() -> None:
594+
_T = TypeVar("_T")
595+
596+
def dep3():
597+
return 123
598+
599+
class GenericClass(Generic[_T]):
600+
def __init__(self, class_val: _T = Depends(dep3)):
601+
self.return_val = class_val
602+
603+
def target(class_val: GenericClass[Tuple[str, int]] = Depends(use_cache=False)) -> None:
604+
return None
605+
606+
g = DependencyGraph(target=target)
607+
for dep_obj in g.subgraphs.keys():
608+
assert dep_obj.param_name == "class_val"
609+
assert dep_obj.dependency == GenericClass[Tuple[str, int]]
610+
assert dep_obj.signature.name == "class_val"
611+
assert dep_obj.signature.annotation == GenericClass[Tuple[str, int]]

0 commit comments

Comments
 (0)