Skip to content

Commit 63a3e73

Browse files
committed
Fixed no-decorated context managers.
Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent 38b2008 commit 63a3e73

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

taskiq_dependencies/dependency.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import inspect
22
import uuid
3+
from contextlib import _AsyncGeneratorContextManager, _GeneratorContextManager
34
from typing import (
45
Any,
5-
AsyncContextManager,
66
AsyncGenerator,
77
Callable,
8-
ContextManager,
98
Coroutine,
109
Dict,
1110
Generator,
@@ -21,7 +20,7 @@
2120

2221
@overload
2322
def Depends(
24-
dependency: Optional[Callable[..., ContextManager[_T]]] = None,
23+
dependency: Optional[Callable[..., "_GeneratorContextManager[_T]"]] = None,
2524
*,
2625
use_cache: bool = True,
2726
kwargs: Optional[Dict[str, Any]] = None,
@@ -31,7 +30,7 @@ def Depends(
3130

3231
@overload
3332
def Depends(
34-
dependency: Optional[Callable[..., AsyncContextManager[_T]]] = None,
33+
dependency: Optional[Callable[..., "_AsyncGeneratorContextManager[_T]"]] = None,
3534
*,
3635
use_cache: bool = True,
3736
kwargs: Optional[Dict[str, Any]] = None,

taskiq_dependencies/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inspect
22
import sys
3-
from contextlib import AsyncContextDecorator, ContextDecorator
3+
from contextlib import _AsyncGeneratorContextManager, _GeneratorContextManager
44
from typing import Any, AsyncContextManager, ContextManager, Optional
55

66
if sys.version_info >= (3, 10):
@@ -39,7 +39,7 @@ def iscontextmanager(obj: Any) -> TypeGuard[ContextManager[Any]]:
3939
:param obj: object to check.
4040
:return: bool that indicates whether the object is a context manager or not.
4141
"""
42-
return issubclass(obj.__class__, ContextDecorator)
42+
return issubclass(obj.__class__, _GeneratorContextManager)
4343

4444

4545
def isasynccontextmanager(obj: Any) -> TypeGuard[AsyncContextManager[Any]]:
@@ -49,4 +49,4 @@ def isasynccontextmanager(obj: Any) -> TypeGuard[AsyncContextManager[Any]]:
4949
:param obj: object to check.
5050
:return: bool that indicates whether the object is a async context manager or not.
5151
"""
52-
return issubclass(obj.__class__, AsyncContextDecorator)
52+
return issubclass(obj.__class__, _AsyncGeneratorContextManager)

0 commit comments

Comments
 (0)