|
1 | 1 | import inspect |
2 | 2 | from collections import defaultdict, deque |
3 | 3 | from graphlib import TopologicalSorter |
4 | | -from typing import Any, Callable, Dict, List, Optional, TypeVar, get_type_hints |
| 4 | +from typing import ( |
| 5 | + Any, |
| 6 | + Callable, |
| 7 | + Dict, |
| 8 | + ForwardRef, |
| 9 | + List, |
| 10 | + Optional, |
| 11 | + TypeVar, |
| 12 | + get_type_hints, |
| 13 | +) |
5 | 14 |
|
6 | 15 | from taskiq_dependencies.ctx import AsyncResolveContext, SyncResolveContext |
7 | 16 | from taskiq_dependencies.dependency import Dependency |
@@ -171,12 +180,22 @@ def _build_graph(self) -> None: # noqa: C901, WPS210 |
171 | 180 | # default vaule. |
172 | 181 | for param_name, param in sign.parameters.items(): |
173 | 182 | default_value = param.default |
174 | | - if hasattr(param.annotation, "__metadata__"): # noqa: WPS421 |
| 183 | + annotation = param.annotation |
| 184 | + if isinstance(param.annotation, str): |
| 185 | + globalns = getattr(origin, "__globals__", {}) |
| 186 | + annotation = ForwardRef( # type: ignore # noqa: WPS437 |
| 187 | + param.annotation, |
| 188 | + )._evaluate( |
| 189 | + globalns, |
| 190 | + None, |
| 191 | + set(), |
| 192 | + ) |
| 193 | + if hasattr(annotation, "__metadata__"): # noqa: WPS421 |
175 | 194 | # We go backwards, |
176 | 195 | # because you may want to override your annotation |
177 | 196 | # and the overriden value will appear to be after |
178 | 197 | # the original `Depends` annotation. |
179 | | - for meta in reversed(param.annotation.__metadata__): |
| 198 | + for meta in reversed(annotation.__metadata__): |
180 | 199 | if isinstance(meta, Dependency): |
181 | 200 | default_value = meta |
182 | 201 | break |
|
0 commit comments