From 294eec1f275fc98965495b31152d780c1dc88cd5 Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Tue, 25 Aug 2020 17:07:17 -0400 Subject: [PATCH] Add stubs for Coroutine providers --- src/dependency_injector/providers.pyi | 27 ++++++++++++++++++++++++++- tests/typing/coroutine.py | 11 +++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/typing/coroutine.py diff --git a/src/dependency_injector/providers.pyi b/src/dependency_injector/providers.pyi index 65e6548e..1dbed5ea 100644 --- a/src/dependency_injector/providers.pyi +++ b/src/dependency_injector/providers.pyi @@ -1,6 +1,17 @@ from __future__ import annotations -from typing import TypeVar, Generic, Type, Callable as _Callable, Any, Tuple, Optional, Dict, Union +from typing import ( + TypeVar, + Generic, + Type, + Callable as _Callable, + Any, + Tuple, + Optional, + Dict, + Union, + Coroutine as _Coroutine, +) Injection = Any T = TypeVar('T') @@ -92,6 +103,20 @@ class CallableDelegate(Delegate): def __init__(self, callable: Callable) -> None: ... +class Coroutine(Callable): ... + + +class DelegatedCoroutine(Coroutine): ... + + +class AbstractCoroutine(Coroutine): + def override(self, provider: Coroutine) -> OverridingContext: ... + + +class CoroutineDelegate(Delegate): + def __init__(self, coroutine: Coroutine) -> None: ... + + class Factory(Provider, Generic[T]): provided_type: Optional[Type] def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ... diff --git a/tests/typing/coroutine.py b/tests/typing/coroutine.py new file mode 100644 index 00000000..839698dd --- /dev/null +++ b/tests/typing/coroutine.py @@ -0,0 +1,11 @@ +from typing import Coroutine + +from dependency_injector import providers + + +async def _coro() -> None: + ... + +# Test 1: to check the return type +provider1 = providers.Coroutine(_coro) +var1: Coroutine = provider1()