Add stubs for Coroutine providers

This commit is contained in:
Roman Mogylatov 2020-08-25 17:07:17 -04:00
parent 027a72d3b1
commit 294eec1f27
2 changed files with 37 additions and 1 deletions

View File

@ -1,6 +1,17 @@
from __future__ import annotations 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 Injection = Any
T = TypeVar('T') T = TypeVar('T')
@ -92,6 +103,20 @@ class CallableDelegate(Delegate):
def __init__(self, callable: Callable) -> None: ... 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]): class Factory(Provider, Generic[T]):
provided_type: Optional[Type] provided_type: Optional[Type]
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ... def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...

11
tests/typing/coroutine.py Normal file
View File

@ -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()