Skip to content

Commit ce1ec11

Browse files
committed
Merge branch 'release/1.2.4'
2 parents e1eb825 + bfdb1a0 commit ce1ec11

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

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.2.3"
3+
version = "1.2.4"
44
description = "FastAPI like dependency injection implementation"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
readme = "README.md"

taskiq_dependencies/ctx.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ def close(self, *args: Any) -> None: # noqa: C901
142142
if exception_found:
143143
try:
144144
dep.throw(*args)
145+
except StopIteration:
146+
continue
145147
except BaseException as exc:
146148
logger.warning(
147149
"Exception found on dependency teardown %s",
@@ -243,6 +245,8 @@ async def close(self, *args: Any) -> None: # noqa: C901
243245
if exception_found:
244246
try:
245247
dep.throw(*args)
248+
except StopIteration:
249+
continue
246250
except BaseException as exc:
247251
logger.warning(
248252
"Exception found on dependency teardown %s",
@@ -257,6 +261,8 @@ async def close(self, *args: Any) -> None: # noqa: C901
257261
if exception_found:
258262
try:
259263
await dep.athrow(*args)
264+
except StopAsyncIteration:
265+
continue
260266
except BaseException as exc:
261267
logger.warning(
262268
"Exception found on dependency teardown %s",

tests/test_graph.py

Lines changed: 41 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, Tuple, TypeVar
44

55
import pytest
66

@@ -571,3 +571,43 @@ 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() -> 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

Comments
 (0)