Replace Coroutine typevar T with T_Any and retrofit assert_type on coroutine

This commit is contained in:
Leonardus Chen 2025-12-08 14:02:10 +07:00
parent 635c755d74
commit b95e22ecb3
2 changed files with 7 additions and 4 deletions

View File

@ -197,7 +197,7 @@ class AbstractCallable(Callable[T]):
class CallableDelegate(Delegate):
def __init__(self, callable: Callable) -> None: ...
class Coroutine(Callable[T]): ...
class Coroutine(Callable[T_Any]): ...
class DelegatedCoroutine(Coroutine[T]): ...
class AbstractCoroutine(Coroutine[T]):

View File

@ -1,4 +1,5 @@
from typing import Awaitable, Coroutine
from typing import Awaitable, Coroutine, Any
from typing_extensions import assert_type
from dependency_injector import providers
@ -8,8 +9,10 @@ async def _coro() -> None: ...
# Test 1: to check the return type
provider1 = providers.Coroutine(_coro)
var1: Awaitable[None] = provider1()
var1 = provider1()
assert_type(var1, Coroutine[Any, Any, None]) # type: ignore[unused-coroutine]
# Test 2: to check string imports
provider2: providers.Coroutine[None] = providers.Coroutine("_coro")
provider2 = providers.Coroutine("_coro")
provider2.set_provides("_coro")
assert_type(provider2, providers.Coroutine[Any])