mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-06-24 09:48:39 +08:00
[asyncio] Add asyncio 3.14 deprecations (#15176)
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from asyncio import iscoroutinefunction
|
||||
from collections.abc import Awaitable, Callable, Coroutine
|
||||
from typing import Any
|
||||
from typing_extensions import assert_type
|
||||
|
||||
|
||||
def test_iscoroutinefunction(
|
||||
def test_iscoroutinefunction_asyncio(
|
||||
x: Callable[[str, int], Coroutine[str, int, bytes]],
|
||||
y: Callable[[str, int], Awaitable[bytes]],
|
||||
z: Callable[[str, int], str | Awaitable[bytes]],
|
||||
xx: object,
|
||||
) -> None:
|
||||
if iscoroutinefunction(x):
|
||||
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
|
||||
# asyncio.iscoroutinefunction is deprecated >= 3.11, expecting a warning.
|
||||
if sys.version_info >= (3, 11):
|
||||
if iscoroutinefunction(x): # pyright: ignore
|
||||
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
|
||||
|
||||
if iscoroutinefunction(y):
|
||||
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])
|
||||
if iscoroutinefunction(y): # pyright: ignore
|
||||
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])
|
||||
|
||||
if iscoroutinefunction(z):
|
||||
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])
|
||||
if iscoroutinefunction(z): # pyright: ignore
|
||||
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])
|
||||
|
||||
if iscoroutinefunction(xx):
|
||||
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])
|
||||
if iscoroutinefunction(xx): # pyright: ignore
|
||||
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])
|
||||
else:
|
||||
if iscoroutinefunction(x):
|
||||
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
|
||||
|
||||
if iscoroutinefunction(y):
|
||||
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])
|
||||
|
||||
if iscoroutinefunction(z):
|
||||
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])
|
||||
|
||||
if iscoroutinefunction(xx):
|
||||
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import inspect
|
||||
from collections.abc import Awaitable, Callable, Coroutine
|
||||
from types import CoroutineType
|
||||
from typing import Any
|
||||
from typing_extensions import assert_type
|
||||
|
||||
|
||||
def test_iscoroutinefunction_inspect(
|
||||
x: Callable[[str, int], Coroutine[str, int, bytes]],
|
||||
y: Callable[[str, int], Awaitable[bytes]],
|
||||
z: Callable[[str, int], str | Awaitable[bytes]],
|
||||
xx: object,
|
||||
) -> None:
|
||||
if inspect.iscoroutinefunction(x):
|
||||
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
|
||||
|
||||
if inspect.iscoroutinefunction(y):
|
||||
assert_type(y, Callable[[str, int], CoroutineType[Any, Any, bytes]])
|
||||
|
||||
if inspect.iscoroutinefunction(z):
|
||||
assert_type(z, Callable[[str, int], CoroutineType[Any, Any, Any]])
|
||||
|
||||
if inspect.iscoroutinefunction(xx):
|
||||
assert_type(xx, Callable[..., CoroutineType[Any, Any, Any]])
|
||||
@@ -17,12 +17,31 @@ if sys.version_info < (3, 11):
|
||||
@deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `async def` instead.")
|
||||
def coroutine(func: _FunctionT) -> _FunctionT: ...
|
||||
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
|
||||
def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ...
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
@overload
|
||||
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
|
||||
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
|
||||
@overload
|
||||
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
|
||||
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
|
||||
@overload
|
||||
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
|
||||
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
|
||||
@overload
|
||||
@deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.")
|
||||
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
|
||||
|
||||
else:
|
||||
# Sometimes needed in Python < 3.11 due to the fact that it supports @coroutine
|
||||
# which was removed in 3.11 which the inspect version doesn't support.
|
||||
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ...
|
||||
@overload
|
||||
def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ...
|
||||
|
||||
Reference in New Issue
Block a user