Skip to content

Commit 32dad9c

Browse files
committed
Merge branch 'release/1.5.0'
2 parents 24626e0 + 280e085 commit 32dad9c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,5 @@ def my_function(
362362
pass
363363

364364
```
365+
366+
Also, please note that if you're using `from __future__ import annotations` it won't work for python <= 3.9. Because the `inspect.signature` function doesn't support it. In all future versions it will work as expected.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq-dependencies"
3-
version = "1.4.2"
3+
version = "1.5.0"
44
description = "FastAPI like dependency injection implementation"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
readme = "README.md"

taskiq_dependencies/graph.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import sys
23
from collections import defaultdict, deque
34
from graphlib import TopologicalSorter
45
from typing import Any, Callable, Dict, List, Optional, TypeVar, get_type_hints
@@ -106,6 +107,12 @@ def _build_graph(self) -> None: # noqa: C901, WPS210
106107
:raises ValueError: if something happened.
107108
"""
108109
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
109116

110117
while dep_deque:
111118
dep = dep_deque.popleft()
@@ -155,16 +162,19 @@ def _build_graph(self) -> None: # noqa: C901, WPS210
155162
# If this is a class, we need to get signature of
156163
# an __init__ method.
157164
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+
)
159169
elif inspect.isfunction(dep.dependency):
160170
# If this is function or an instance of a class, we get it's type hints.
161171
hints = get_type_hints(dep.dependency)
162-
sign = inspect.signature(origin) # type: ignore
172+
sign = inspect.signature(origin, **signature_kwargs) # type: ignore
163173
else:
164174
hints = get_type_hints(
165175
dep.dependency.__call__, # type: ignore # noqa: WPS609
166176
)
167-
sign = inspect.signature(origin) # type: ignore
177+
sign = inspect.signature(origin, **signature_kwargs) # type: ignore
168178

169179
# Now we need to iterate over parameters, to
170180
# find all parameters, that have TaskiqDepends as it's

0 commit comments

Comments
 (0)