|
1 | 1 | import asyncio |
2 | 2 | import uuid |
3 | | -from typing import Any, AsyncGenerator, Generator, Generic, TypeVar |
| 3 | +from typing import Any, AsyncGenerator, Generator, Generic, Tuple, TypeVar |
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
@@ -571,3 +571,43 @@ def target(my_dep: GenericClass[int] = Depends(func_dep)) -> int: |
571 | 571 | result = target(**g.resolve_kwargs()) |
572 | 572 |
|
573 | 573 | 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() -> int: |
| 597 | + return 123 |
| 598 | + |
| 599 | + class GenericClass(Generic[_T]): |
| 600 | + def __init__(self, class_val: int = Depends(dep3)): |
| 601 | + self.return_val = class_val |
| 602 | + |
| 603 | + def target( |
| 604 | + class_val: GenericClass[Tuple[str, int]] = Depends(use_cache=False), |
| 605 | + ) -> None: |
| 606 | + return None |
| 607 | + |
| 608 | + g = DependencyGraph(target=target) |
| 609 | + for dep_obj in g.subgraphs.keys(): |
| 610 | + assert dep_obj.param_name == "class_val" |
| 611 | + assert dep_obj.dependency == GenericClass[Tuple[str, int]] |
| 612 | + assert dep_obj.signature.name == "class_val" |
| 613 | + assert dep_obj.signature.annotation == GenericClass[Tuple[str, int]] |
0 commit comments