diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index 160bd896469e..52377950de58 100644 --- a/stdlib/@tests/test_cases/asyncio/check_coroutines.py +++ b/stdlib/@tests/test_cases/asyncio/check_coroutines.py @@ -1,25 +1,47 @@ 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 -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): + # Type ignores are neeeded due to deprecation of iscoroutinefunction in 3.14 + if iscoroutinefunction(x): # type: ignore assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]]) - if iscoroutinefunction(y): + if iscoroutinefunction(y): # type: ignore assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]]) - if iscoroutinefunction(z): + if iscoroutinefunction(z): # type: ignore assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]]) - if iscoroutinefunction(xx): + if iscoroutinefunction(xx): # type: ignore 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/argparse.pyi b/stdlib/argparse.pyi index 312093c0aa55..d358378a989c 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -91,15 +91,38 @@ class _ActionsContainer: version: str = ..., **kwargs: Any, ) -> Action: ... - def add_argument_group( - self, - title: str | None = None, - description: str | None = None, - *, - prefix_chars: str = ..., - argument_default: Any = ..., - conflict_handler: str = ..., - ) -> _ArgumentGroup: ... + if sys.version_info >= (3, 14): + @overload + def add_argument_group( + self, + title: str | None = None, + description: str | None = None, + *, + argument_default: Any = ..., + conflict_handler: str = ..., + ) -> _ArgumentGroup: ... + @overload + @deprecated("Passing 'prefix_chars' to add_argument_group() is deprecated") + def add_argument_group( + self, + title: str | None = None, + description: str | None = None, + *, + prefix_chars: str = ..., + argument_default: Any = ..., + conflict_handler: str = ..., + ) -> _ArgumentGroup: ... + else: + def add_argument_group( + self, + title: str | None = None, + description: str | None = None, + *, + prefix_chars: str = ..., + argument_default: Any = ..., + conflict_handler: str = ..., + ) -> _ArgumentGroup: ... + def add_mutually_exclusive_group(self, *, required: bool = False) -> _MutuallyExclusiveGroup: ... def _add_action(self, action: _ActionT) -> _ActionT: ... def _remove_action(self, action: Action) -> None: ... diff --git a/stdlib/asyncio/coroutines.pyi b/stdlib/asyncio/coroutines.pyi index 8ef30b3d3198..23e5fcdb2741 100644 --- a/stdlib/asyncio/coroutines.pyi +++ b/stdlib/asyncio/coroutines.pyi @@ -1,7 +1,7 @@ import sys from collections.abc import Awaitable, Callable, Coroutine from typing import Any, TypeVar, overload -from typing_extensions import ParamSpec, TypeGuard, TypeIs +from typing_extensions import ParamSpec, TypeGuard, TypeIs, deprecated # Keep asyncio.__all__ updated with any changes to __all__ here if sys.version_info >= (3, 11): @@ -17,11 +17,15 @@ if sys.version_info < (3, 11): def coroutine(func: _FunctionT) -> _FunctionT: ... @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]]]: ... def iscoroutine(obj: object) -> TypeIs[Coroutine[Any, Any, Any]]: ... diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index 49f200dcdcae..a980c62b04d6 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -183,6 +183,7 @@ if sys.platform != "win32": if sys.version_info >= (3, 14): _DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy + else: DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy diff --git a/stdlib/codecs.pyi b/stdlib/codecs.pyi index 579d09c66a1b..45c4111289b4 100644 --- a/stdlib/codecs.pyi +++ b/stdlib/codecs.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer from abc import abstractmethod from collections.abc import Callable, Generator, Iterable from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "register", @@ -149,6 +149,7 @@ def getincrementaldecoder(encoding: _BufferedEncoding) -> _BufferedIncrementalDe def getincrementaldecoder(encoding: str) -> _IncrementalDecoder: ... def getreader(encoding: str) -> _StreamReader: ... def getwriter(encoding: str) -> _StreamWriter: ... +@deprecated("codecs.open() is deprecated. Use open() instead.") def open( filename: str, mode: str = "r", encoding: str | None = None, errors: str = "strict", buffering: int = -1 ) -> StreamReaderWriter: ... diff --git a/stdlib/pathlib/__init__.pyi b/stdlib/pathlib/__init__.pyi index b84fc69313a1..dde13c42363d 100644 --- a/stdlib/pathlib/__init__.pyi +++ b/stdlib/pathlib/__init__.pyi @@ -65,6 +65,7 @@ class PurePath(PathLike[str]): def __rtruediv__(self, key: StrPath) -> Self: ... def __bytes__(self) -> bytes: ... def as_posix(self) -> str: ... + @deprecated("PurePath.as_uri() is deprecated. Use Path.as_uri() instead.") def as_uri(self) -> str: ... def is_absolute(self) -> bool: ... def is_reserved(self) -> bool: ... @@ -163,7 +164,6 @@ class Path(PurePath): def mkdir(self, mode: int = 0o777, parents: bool = False, exist_ok: bool = False) -> None: ... if sys.version_info >= (3, 14): - @property def info(self) -> PathInfo: ... @overload @@ -300,6 +300,8 @@ class Path(PurePath): self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... ) -> Iterator[tuple[Self, list[str], list[str]]]: ... + def as_uri(self) -> str: ... + class PosixPath(Path, PurePosixPath): ... class WindowsPath(Path, PureWindowsPath): ... diff --git a/stdlib/pdb.pyi b/stdlib/pdb.pyi index ad69fcab16de..ebccf4140a02 100644 --- a/stdlib/pdb.pyi +++ b/stdlib/pdb.pyi @@ -7,7 +7,7 @@ from inspect import _SourceObjectType from linecache import _ModuleGlobals from types import CodeType, FrameType, TracebackType from typing import IO, Any, ClassVar, Final, Literal, TypeVar -from typing_extensions import ParamSpec, Self, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias, deprecated __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", "post_mortem", "help"] if sys.version_info >= (3, 14): @@ -59,7 +59,12 @@ class Pdb(Bdb, Cmd): stack: list[tuple[FrameType, int]] curindex: int curframe: FrameType | None - curframe_locals: Mapping[str, Any] + if sys.version_info >= (3, 13): + @property + @deprecated("curframe_locals is deprecated. Derived debuggers should access pdb.Pdb.curframe.f_locals instead.") + def curframe_locals(self) -> Mapping[str, Any]: ... + else: + curframe_locals: Mapping[str, Any] if sys.version_info >= (3, 14): mode: _Mode | None colorize: bool