From a75f50254db4590c4c1559754201af496082dd40 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Thu, 25 Dec 2025 14:28:35 -0600 Subject: [PATCH 1/9] Add asyncio 3.14 deprecations --- .../test_cases/asyncio/check_coroutines.py | 52 ++++++++++++++++--- stdlib/asyncio/coroutines.pyi | 35 ++++++++++--- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index 160bd896469e..b2c921cb0e70 100644 --- a/stdlib/@tests/test_cases/asyncio/check_coroutines.py +++ b/stdlib/@tests/test_cases/asyncio/check_coroutines.py @@ -1,25 +1,61 @@ from __future__ import annotations +import inspect from asyncio import iscoroutinefunction from collections.abc import Awaitable, Callable, Coroutine +from types import CoroutineType from typing import Any from typing_extensions import assert_type +import sys -def test_iscoroutinefunction( +# asyncio.iscoroutinefunction is deprecated, expecting a warning. +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): + if sys.version_info >= (3, 11): + if iscoroutinefunction(x): # pyright: ignore + assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]]) + + if iscoroutinefunction(y): # pyright: ignore + assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]]) + + if iscoroutinefunction(z): # pyright: ignore + assert_type(z, Callable[[str, int], 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]]) + + +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 iscoroutinefunction(y): - assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]]) + if inspect.iscoroutinefunction(y): + assert_type(y, Callable[[str, int], CoroutineType[Any, Any, bytes]]) - if iscoroutinefunction(z): - assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]]) + if inspect.iscoroutinefunction(z): + assert_type(z, Callable[[str, int], CoroutineType[Any, Any, Any]]) - if iscoroutinefunction(xx): - assert_type(xx, Callable[..., Coroutine[Any, Any, Any]]) + if inspect.iscoroutinefunction(xx): + assert_type(xx, Callable[..., CoroutineType[Any, Any, Any]]) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index 59212f4ec398..a521ce7cba5d 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -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 in Python 3.14; use inspect.iscoroutinefunction() instead") + def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ... + @overload + @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ... + @overload + @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ... + @overload + @deprecated("Deprecated in 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]]]: ... From 5de657f7524ec239acc89c3e9bc2ad60ca8c7726 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 25 Dec 2025 20:31:44 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/@tests/test_cases/asyncio/check_coroutines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index b2c921cb0e70..bb16400d6f7b 100644 --- a/stdlib/@tests/test_cases/asyncio/check_coroutines.py +++ b/stdlib/@tests/test_cases/asyncio/check_coroutines.py @@ -1,12 +1,12 @@ from __future__ import annotations import inspect +import sys from asyncio import iscoroutinefunction from collections.abc import Awaitable, Callable, Coroutine from types import CoroutineType from typing import Any from typing_extensions import assert_type -import sys # asyncio.iscoroutinefunction is deprecated, expecting a warning. From a3a3c0f3828f51745af9941a386b76d654354413 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Fri, 26 Dec 2025 13:26:00 -0600 Subject: [PATCH 3/9] Update stdlib/asyncio/coroutines.pyi Co-authored-by: Semyon Moroz --- stdlib/asyncio/coroutines.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index a521ce7cba5d..e8676716faea 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -30,7 +30,7 @@ if sys.version_info >= (3, 11): @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") def iscoroutinefunction(func: Callable[_P, object]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, Any]]]: ... @overload - @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: object) -> TypeGuard[Callable[..., Coroutine[Any, Any, Any]]]: ... else: From 134609c557674a9750d145e0f8d9a5169617d145 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Fri, 26 Dec 2025 13:26:06 -0600 Subject: [PATCH 4/9] Update stdlib/asyncio/coroutines.pyi Co-authored-by: Semyon Moroz --- stdlib/asyncio/coroutines.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index e8676716faea..42ea86696fda 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -27,7 +27,7 @@ if sys.version_info >= (3, 11): @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") def iscoroutinefunction(func: Callable[_P, Awaitable[_T]]) -> TypeGuard[Callable[_P, Coroutine[Any, Any, _T]]]: ... @overload - @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + @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.") From 5a4ac373fb588ddfdaae46f2273112e4e288cac4 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Fri, 26 Dec 2025 13:26:12 -0600 Subject: [PATCH 5/9] Update stdlib/asyncio/coroutines.pyi Co-authored-by: Semyon Moroz --- stdlib/asyncio/coroutines.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index 42ea86696fda..a9444c464015 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -21,7 +21,7 @@ def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ... if sys.version_info >= (3, 11): @overload - @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ... @overload @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") From cdf3e53ca6526dea2d24061317fd95a16855326d Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Fri, 26 Dec 2025 13:26:17 -0600 Subject: [PATCH 6/9] Update stdlib/asyncio/coroutines.pyi Co-authored-by: Semyon Moroz --- stdlib/asyncio/coroutines.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index a9444c464015..777961d80441 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -24,7 +24,7 @@ if sys.version_info >= (3, 11): @deprecated("Deprecated since Python 3.14. Use `inspect.iscoroutinefunction()` instead.") def iscoroutinefunction(func: Callable[..., Coroutine[Any, Any, Any]]) -> bool: ... @overload - @deprecated("Deprecated in Python 3.14; use inspect.iscoroutinefunction() instead") + @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.") From cbc3aee8fb0f559cec31a1c806e686125c64edc1 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Mon, 16 Jun 2025 14:00:15 -0500 Subject: [PATCH 7/9] Add 3.14 deprecations --- stdlib/@tests/test_cases/asyncio/check_coroutines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index bb16400d6f7b..fd04e21cc9e1 100644 --- a/stdlib/@tests/test_cases/asyncio/check_coroutines.py +++ b/stdlib/@tests/test_cases/asyncio/check_coroutines.py @@ -9,13 +9,13 @@ from typing_extensions import assert_type -# asyncio.iscoroutinefunction is deprecated, expecting a warning. 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: + # 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]]) From 66b70c048400b06d27a5f0d2a72edc3e7a8ddddc Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Fri, 26 Dec 2025 13:45:37 -0600 Subject: [PATCH 8/9] Trigger CI pipeline From 300644c90346e48bea5e2e5722718cd8a9709f3b Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 27 Dec 2025 15:41:55 -0600 Subject: [PATCH 9/9] split up tests --- .../test_cases/asyncio/check_coroutines.py | 21 --------------- stdlib/@tests/test_cases/check_inspect.py | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 stdlib/@tests/test_cases/check_inspect.py diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index fd04e21cc9e1..6062ca55146a 100644 --- a/stdlib/@tests/test_cases/asyncio/check_coroutines.py +++ b/stdlib/@tests/test_cases/asyncio/check_coroutines.py @@ -1,10 +1,8 @@ from __future__ import annotations -import inspect import sys from asyncio import iscoroutinefunction from collections.abc import Awaitable, Callable, Coroutine -from types import CoroutineType from typing import Any from typing_extensions import assert_type @@ -40,22 +38,3 @@ def test_iscoroutinefunction_asyncio( if iscoroutinefunction(xx): assert_type(xx, Callable[..., Coroutine[Any, Any, Any]]) - - -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]]) diff --git a/stdlib/@tests/test_cases/check_inspect.py b/stdlib/@tests/test_cases/check_inspect.py new file mode 100644 index 000000000000..e7ef3d25cf6e --- /dev/null +++ b/stdlib/@tests/test_cases/check_inspect.py @@ -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]])