[ty] Sync vendored typeshed stubs (#21178)

Close and reopen this PR to trigger CI

---------

Co-authored-by: typeshedbot <>
This commit is contained in:
github-actions[bot] 2025-10-31 21:03:40 -04:00 committed by GitHub
parent 521217bb90
commit a151f9746d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 97 additions and 68 deletions

View file

@ -7,10 +7,10 @@
## About
Typeshed contains external type annotations for the Python standard library
and Python builtins, as well as third party packages as contributed by
and Python builtins, as well as third-party packages that are contributed by
people external to those projects.
This data can e.g. be used for static analysis, type checking, type inference,
This data can, e.g., be used for static analysis, type checking, type inference,
and autocompletion.
For information on how to use typeshed, read below. Information for
@ -29,8 +29,8 @@ If you're just using a type checker (e.g. [mypy](https://github.com/python/mypy/
[pyright](https://github.com/microsoft/pyright), or PyCharm's built-in type
checker), as opposed to
developing it, you don't need to interact with the typeshed repo at
all: a copy of standard library part of typeshed is bundled with type checkers.
And type stubs for third party packages and modules you are using can
all: a copy of the standard library part of typeshed is bundled with type checkers.
And type stubs for third-party packages and modules you are using can
be installed from PyPI. For example, if you are using `html5lib` and `requests`,
you can install the type stubs using
@ -70,7 +70,7 @@ package you're using, each with its own tradeoffs:
type checking due to changes in the stubs.
Another risk of this strategy is that stubs often lag behind
the package being stubbed. You might want to force the package being stubbed
the package that is being stubbed. You might want to force the package being stubbed
to a certain minimum version because it fixes a critical bug, but if
correspondingly updated stubs have not been released, your type
checking results may not be fully accurate.
@ -119,6 +119,6 @@ a review of your type annotations or stubs outside of typeshed, head over to
[our discussion forum](https://github.com/python/typing/discussions).
For less formal discussion, try the typing chat room on
[gitter.im](https://gitter.im/python/typing). Some typeshed maintainers
are almost always present; feel free to find us there and we're happy
are almost always present; feel free to find us there, and we're happy
to chat. Substantive technical discussion will be directed to the
issue tracker.

View file

@ -1 +1 @@
d6f4a0f7102b1400a21742cf9b7ea93614e2b6ec
bf7214784877c52638844c065360d4814fae4c65

View file

@ -4525,6 +4525,10 @@ class BaseException:
def __setstate__(self, state: dict[str, Any] | None, /) -> None: ...
def with_traceback(self, tb: TracebackType | None, /) -> Self:
"""Set self.__traceback__ to tb and return self."""
# Necessary for security-focused static analyzers (e.g, pysa)
# See https://github.com/python/typeshed/pull/14900
def __str__(self) -> str: ... # noqa: Y029
def __repr__(self) -> str: ... # noqa: Y029
if sys.version_info >= (3, 11):
# only present after add_note() is called
__notes__: list[str]

View file

@ -67,7 +67,7 @@ def isinf(z: _C, /) -> bool:
def isnan(z: _C, /) -> bool:
"""Checks if the real or imaginary part of z not a number (NaN)."""
def log(x: _C, base: _C = ..., /) -> complex:
def log(z: _C, base: _C = ..., /) -> complex:
"""log(z[, base]) -> the logarithm of z to the given base.
If the base is not specified, returns the natural logarithm (base e) of z.

View file

@ -6,7 +6,7 @@ from _typeshed import FileDescriptorOrPath, Unused
from abc import ABC, abstractmethod
from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
from types import TracebackType
from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
from typing import Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
from typing_extensions import ParamSpec, Self, TypeAlias
__all__ = [
@ -32,7 +32,6 @@ if sys.version_info >= (3, 11):
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_T_io = TypeVar("_T_io", bound=IO[str] | None)
_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None)
_F = TypeVar("_F", bound=Callable[..., Any])
_G_co = TypeVar("_G_co", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True)
@ -275,13 +274,23 @@ class suppress(AbstractContextManager[None, bool]):
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
) -> bool: ...
class _RedirectStream(AbstractContextManager[_T_io, None]):
def __init__(self, new_target: _T_io) -> None: ...
# This is trying to describe what is needed for (most?) uses
# of `redirect_stdout` and `redirect_stderr`.
# https://github.com/python/typeshed/issues/14903
@type_check_only
class _SupportsRedirect(Protocol):
def write(self, s: str, /) -> int: ...
def flush(self) -> None: ...
_SupportsRedirectT = TypeVar("_SupportsRedirectT", bound=_SupportsRedirect | None)
class _RedirectStream(AbstractContextManager[_SupportsRedirectT, None]):
def __init__(self, new_target: _SupportsRedirectT) -> None: ...
def __exit__(
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
) -> None: ...
class redirect_stdout(_RedirectStream[_T_io]):
class redirect_stdout(_RedirectStream[_SupportsRedirectT]):
"""Context manager for temporarily redirecting stdout to another file.
# How to send help() to stderr
@ -294,7 +303,7 @@ class redirect_stdout(_RedirectStream[_T_io]):
help(pow)
"""
class redirect_stderr(_RedirectStream[_T_io]):
class redirect_stderr(_RedirectStream[_SupportsRedirectT]):
"""Context manager for temporarily redirecting stderr to another file."""
class _BaseExitStack(Generic[_ExitT_co]):

View file

@ -623,6 +623,8 @@ if sys.version_info >= (3, 11):
the module is the last module in case of a multi-module name
"""
def show_flag_values(value: int) -> list[int]: ...
if sys.version_info >= (3, 12):
# The body of the class is the same, but the base classes are different.
class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases

View file

@ -752,6 +752,9 @@ environ: _Environ[str]
if sys.platform != "win32":
environb: _Environ[bytes]
if sys.version_info >= (3, 14):
def reload_environ() -> None: ...
if sys.version_info >= (3, 11) or sys.platform != "win32":
EX_OK: Final[int]

View file

@ -578,6 +578,21 @@ def _getframe(depth: int = 0, /) -> FrameType:
only.
"""
# documented -- see https://docs.python.org/3/library/sys.html#sys._current_exceptions
if sys.version_info >= (3, 12):
def _current_exceptions() -> dict[int, BaseException | None]:
"""Return a dict mapping each thread's identifier to its current raised exception.
This function should be used for specialized purposes only.
"""
else:
def _current_exceptions() -> dict[int, OptExcInfo]:
"""Return a dict mapping each thread's identifier to its current raised exception.
This function should be used for specialized purposes only.
"""
if sys.version_info >= (3, 12):
def _getframemodulename(depth: int = 0) -> str | None:
"""Return the name of the module for a calling frame.
@ -627,6 +642,9 @@ def exit(status: _ExitCode = None, /) -> NoReturn:
exit status will be one (i.e., failure).
"""
if sys.platform == "android": # noqa: Y008
def getandroidapilevel() -> int: ...
def getallocatedblocks() -> int:
"""Return the number of memory blocks currently allocated."""
@ -949,3 +967,9 @@ if sys.version_info >= (3, 14):
script (str|bytes): The path to a file containing
the Python code to be executed.
"""
def _is_immortal(op: object, /) -> bool:
"""Return True if the given object is "immortal" per PEP 683.
This function should be used for specialized purposes only.
"""

View file

@ -2,7 +2,7 @@
import sys
from typing import IO, Any, Literal, overload
from typing_extensions import deprecated
from typing_extensions import LiteralString, deprecated
__all__ = [
"get_config_h_filename",
@ -47,8 +47,10 @@ def get_scheme_names() -> tuple[str, ...]:
"""Return a tuple containing the schemes names."""
if sys.version_info >= (3, 10):
def get_default_scheme() -> str: ...
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> str: ...
def get_default_scheme() -> LiteralString: ...
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> LiteralString: ...
# Documented -- see https://docs.python.org/3/library/sysconfig.html#sysconfig._get_preferred_schemes
def _get_preferred_schemes() -> dict[Literal["prefix", "home", "user"], LiteralString]: ...
def get_path_names() -> tuple[str, ...]:
"""Return a tuple containing the paths names."""

View file

@ -1721,17 +1721,22 @@ class Wm:
if sys.platform == "darwin":
@overload
def wm_attributes(self, option: Literal["-modified"], /) -> bool:
"""Return or sets platform specific attributes.
"""This subcommand returns or sets platform specific attributes
When called with a single argument return_python_dict=True,
return a dict of the platform specific attributes and their values.
When called without arguments or with a single argument
return_python_dict=False, return a tuple containing intermixed
attribute names with the minus prefix and their values.
The first form returns a list of the platform specific flags and
their values. The second form returns the value for the specific
option. The third form sets one or more of the values. The values
are as follows:
When called with a single string value, return the value for the
specific option. When called with keyword arguments, set the
corresponding attributes.
On Windows, -disabled gets or sets whether the window is in a
disabled state. -toolwindow gets or sets the style of the window
to toolwindow (as defined in the MSDN). -topmost gets or sets
whether this is a topmost window (displays above all other
windows).
On Macintosh, XXXXX
On Unix, there are currently no special attribute values.
"""
@overload
@ -1803,20 +1808,7 @@ class Wm:
def wm_attributes(self, option: Literal["topmost"], /) -> bool: ...
if sys.platform == "darwin":
@overload
def wm_attributes(self, option: Literal["modified"], /) -> bool:
"""Return or sets platform specific attributes.
When called with a single argument return_python_dict=True,
return a dict of the platform specific attributes and their values.
When called without arguments or with a single argument
return_python_dict=False, return a tuple containing intermixed
attribute names with the minus prefix and their values.
When called with a single string value, return the value for the
specific option. When called with keyword arguments, set the
corresponding attributes.
"""
def wm_attributes(self, option: Literal["modified"], /) -> bool: ...
@overload
def wm_attributes(self, option: Literal["notify"], /) -> bool: ...
@overload
@ -1876,17 +1868,22 @@ class Wm:
if sys.platform == "darwin":
@overload
def wm_attributes(self, option: Literal["-modified"], value: bool, /) -> Literal[""]:
"""Return or sets platform specific attributes.
"""This subcommand returns or sets platform specific attributes
When called with a single argument return_python_dict=True,
return a dict of the platform specific attributes and their values.
When called without arguments or with a single argument
return_python_dict=False, return a tuple containing intermixed
attribute names with the minus prefix and their values.
The first form returns a list of the platform specific flags and
their values. The second form returns the value for the specific
option. The third form sets one or more of the values. The values
are as follows:
When called with a single string value, return the value for the
specific option. When called with keyword arguments, set the
corresponding attributes.
On Windows, -disabled gets or sets whether the window is in a
disabled state. -toolwindow gets or sets the style of the window
to toolwindow (as defined in the MSDN). -topmost gets or sets
whether this is a topmost window (displays above all other
windows).
On Macintosh, XXXXX
On Unix, there are currently no special attribute values.
"""
@overload
@ -1950,19 +1947,7 @@ class Wm:
titlepath: str = ...,
topmost: bool = ...,
transparent: bool = ...,
) -> None:
"""Return or sets platform specific attributes.
When called with a single argument return_python_dict=True,
return a dict of the platform specific attributes and their values.
When called without arguments or with a single argument
return_python_dict=False, return a tuple containing intermixed
attribute names with the minus prefix and their values.
When called with a single string value, return the value for the
specific option. When called with keyword arguments, set the
corresponding attributes.
"""
) -> None: ...
elif sys.platform == "win32":
@overload
def wm_attributes(

View file

@ -669,7 +669,7 @@ class TurtleScreen(TurtleScreenBase):
['arrow', 'blank', 'circle', ... , 'turtle']
"""
def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None:
def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None:
"""Bind fun to mouse-click event on canvas.
Arguments:
@ -2540,7 +2540,7 @@ def getshapes() -> list[str]:
['arrow', 'blank', 'circle', ... , 'turtle']
"""
def onclick(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None:
def onclick(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None:
"""Bind fun to mouse-click event on this turtle on canvas.
Arguments:
@ -3960,7 +3960,7 @@ def getturtle() -> Turtle:
getpen = getturtle
def onrelease(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None:
def onrelease(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None:
"""Bind fun to mouse-button-release event on this turtle on canvas.
Arguments:
@ -3983,7 +3983,7 @@ def onrelease(fun: Callable[[float, float], object], btn: int = 1, add: Any | No
transparent.
"""
def ondrag(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None:
def ondrag(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None:
"""Bind fun to mouse-move event on this turtle on canvas.
Arguments:

View file

@ -41,8 +41,8 @@ Z_RLE: Final = 3
Z_SYNC_FLUSH: Final = 2
Z_TREES: Final = 6
if sys.version_info >= (3, 14) and sys.platform == "win32":
# Available when zlib was built with zlib-ng, usually only on Windows
if sys.version_info >= (3, 14):
# Available when zlib was built with zlib-ng
ZLIBNG_VERSION: Final[str]
class error(Exception): ...