|
1 | 1 | import inspect |
| 2 | +import sys |
2 | 3 | from collections import defaultdict, deque |
3 | 4 | from graphlib import TopologicalSorter |
4 | 5 | from typing import Any, Callable, Dict, List, Optional, TypeVar, get_type_hints |
@@ -106,6 +107,12 @@ def _build_graph(self) -> None: # noqa: C901, WPS210 |
106 | 107 | :raises ValueError: if something happened. |
107 | 108 | """ |
108 | 109 | dep_deque = deque([Dependency(self.target, use_cache=True)]) |
| 110 | + # This is for `from __future__ import annotations` support. |
| 111 | + # We need to use `eval_str` argument, because |
| 112 | + # signature of the function is a string, not an object. |
| 113 | + signature_kwargs: Dict[str, Any] = {} |
| 114 | + if sys.version_info >= (3, 10): |
| 115 | + signature_kwargs["eval_str"] = True |
109 | 116 |
|
110 | 117 | while dep_deque: |
111 | 118 | dep = dep_deque.popleft() |
@@ -155,16 +162,19 @@ def _build_graph(self) -> None: # noqa: C901, WPS210 |
155 | 162 | # If this is a class, we need to get signature of |
156 | 163 | # an __init__ method. |
157 | 164 | hints = get_type_hints(origin.__init__) # noqa: WPS609 |
158 | | - sign = inspect.signature(origin.__init__) # noqa: WPS609 |
| 165 | + sign = inspect.signature( |
| 166 | + origin.__init__, # noqa: WPS609 |
| 167 | + **signature_kwargs, |
| 168 | + ) |
159 | 169 | elif inspect.isfunction(dep.dependency): |
160 | 170 | # If this is function or an instance of a class, we get it's type hints. |
161 | 171 | hints = get_type_hints(dep.dependency) |
162 | | - sign = inspect.signature(origin) # type: ignore |
| 172 | + sign = inspect.signature(origin, **signature_kwargs) # type: ignore |
163 | 173 | else: |
164 | 174 | hints = get_type_hints( |
165 | 175 | dep.dependency.__call__, # type: ignore # noqa: WPS609 |
166 | 176 | ) |
167 | | - sign = inspect.signature(origin) # type: ignore |
| 177 | + sign = inspect.signature(origin, **signature_kwargs) # type: ignore |
168 | 178 |
|
169 | 179 | # Now we need to iterate over parameters, to |
170 | 180 | # find all parameters, that have TaskiqDepends as it's |
|
0 commit comments