diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 5645abe9fcbd..594b6f3044c1 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -146,6 +146,8 @@ typing.SupportsRound.__type_params__ typing_extensions.SupportsAbs.__type_params__ typing_extensions.SupportsRound.__type_params__ +# Don't always exist at runtime +(pdb.Pdb.curframe_locals)? # ============================================================= # Allowlist entries that cannot or should not be fixed; >= 3.11 diff --git a/stdlib/@tests/test_cases/asyncio/check_coroutines.py b/stdlib/@tests/test_cases/asyncio/check_coroutines.py index 160bd896469e..5990ac7ffb3b 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( +# 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 iscoroutinefunction(x): # pyright: ignore assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]]) - if iscoroutinefunction(y): + if iscoroutinefunction(y): # pyright: ignore assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]]) - if iscoroutinefunction(z): + if iscoroutinefunction(z): # pyright: ignore assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]]) - if iscoroutinefunction(xx): + if iscoroutinefunction(xx): # pyright: 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 b9fa31139c3c..102228377882 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -91,15 +91,40 @@ 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's type must be valid for the arguments in the group + 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's type must be valid for the arguments in the group + 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/codecs.pyi b/stdlib/codecs.pyi index 15e184fc1038..3f9932b4322d 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, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "register", @@ -159,6 +159,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 774478bb2ff4..3dae02c3f2b8 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: ... if sys.version_info >= (3, 13): @@ -306,6 +307,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..cd243ac61a1d 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,15 @@ 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]: ... + @curframe_locals.setter + @deprecated("curframe_locals is deprecated. Derived debuggers should access pdb.Pdb.curframe.f_locals instead.") + def curframe_locals(self, value: Mapping[str, Any]) -> None: ... + else: + curframe_locals: Mapping[str, Any] if sys.version_info >= (3, 14): mode: _Mode | None colorize: bool