Skip to content

Commit a151f97

Browse files
[ty] Sync vendored typeshed stubs (#21178)
Close and reopen this PR to trigger CI --------- Co-authored-by: typeshedbot <>
1 parent 521217b commit a151f97

File tree

12 files changed

+97
-68
lines changed

12 files changed

+97
-68
lines changed

crates/ty_vendored/vendor/typeshed/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
## About
88

99
Typeshed contains external type annotations for the Python standard library
10-
and Python builtins, as well as third party packages as contributed by
10+
and Python builtins, as well as third-party packages that are contributed by
1111
people external to those projects.
1212

13-
This data can e.g. be used for static analysis, type checking, type inference,
13+
This data can, e.g., be used for static analysis, type checking, type inference,
1414
and autocompletion.
1515

1616
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/
2929
[pyright](https://github.com/microsoft/pyright), or PyCharm's built-in type
3030
checker), as opposed to
3131
developing it, you don't need to interact with the typeshed repo at
32-
all: a copy of standard library part of typeshed is bundled with type checkers.
33-
And type stubs for third party packages and modules you are using can
32+
all: a copy of the standard library part of typeshed is bundled with type checkers.
33+
And type stubs for third-party packages and modules you are using can
3434
be installed from PyPI. For example, if you are using `html5lib` and `requests`,
3535
you can install the type stubs using
3636

@@ -70,7 +70,7 @@ package you're using, each with its own tradeoffs:
7070
type checking due to changes in the stubs.
7171

7272
Another risk of this strategy is that stubs often lag behind
73-
the package being stubbed. You might want to force the package being stubbed
73+
the package that is being stubbed. You might want to force the package being stubbed
7474
to a certain minimum version because it fixes a critical bug, but if
7575
correspondingly updated stubs have not been released, your type
7676
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
119119
[our discussion forum](https://github.com/python/typing/discussions).
120120
For less formal discussion, try the typing chat room on
121121
[gitter.im](https://gitter.im/python/typing). Some typeshed maintainers
122-
are almost always present; feel free to find us there and we're happy
122+
are almost always present; feel free to find us there, and we're happy
123123
to chat. Substantive technical discussion will be directed to the
124124
issue tracker.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
d6f4a0f7102b1400a21742cf9b7ea93614e2b6ec
1+
bf7214784877c52638844c065360d4814fae4c65

crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4525,6 +4525,10 @@ class BaseException:
45254525
def __setstate__(self, state: dict[str, Any] | None, /) -> None: ...
45264526
def with_traceback(self, tb: TracebackType | None, /) -> Self:
45274527
"""Set self.__traceback__ to tb and return self."""
4528+
# Necessary for security-focused static analyzers (e.g, pysa)
4529+
# See https://github.com/python/typeshed/pull/14900
4530+
def __str__(self) -> str: ... # noqa: Y029
4531+
def __repr__(self) -> str: ... # noqa: Y029
45284532
if sys.version_info >= (3, 11):
45294533
# only present after add_note() is called
45304534
__notes__: list[str]

crates/ty_vendored/vendor/typeshed/stdlib/cmath.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def isinf(z: _C, /) -> bool:
6767
def isnan(z: _C, /) -> bool:
6868
"""Checks if the real or imaginary part of z not a number (NaN)."""
6969

70-
def log(x: _C, base: _C = ..., /) -> complex:
70+
def log(z: _C, base: _C = ..., /) -> complex:
7171
"""log(z[, base]) -> the logarithm of z to the given base.
7272
7373
If the base is not specified, returns the natural logarithm (base e) of z.

crates/ty_vendored/vendor/typeshed/stdlib/contextlib.pyi

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from _typeshed import FileDescriptorOrPath, Unused
66
from abc import ABC, abstractmethod
77
from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator
88
from types import TracebackType
9-
from typing import IO, Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
9+
from typing import Any, Generic, Protocol, TypeVar, overload, runtime_checkable, type_check_only
1010
from typing_extensions import ParamSpec, Self, TypeAlias
1111

1212
__all__ = [
@@ -32,7 +32,6 @@ if sys.version_info >= (3, 11):
3232

3333
_T = TypeVar("_T")
3434
_T_co = TypeVar("_T_co", covariant=True)
35-
_T_io = TypeVar("_T_io", bound=IO[str] | None)
3635
_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None)
3736
_F = TypeVar("_F", bound=Callable[..., Any])
3837
_G_co = TypeVar("_G_co", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True)
@@ -275,13 +274,23 @@ class suppress(AbstractContextManager[None, bool]):
275274
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
276275
) -> bool: ...
277276

278-
class _RedirectStream(AbstractContextManager[_T_io, None]):
279-
def __init__(self, new_target: _T_io) -> None: ...
277+
# This is trying to describe what is needed for (most?) uses
278+
# of `redirect_stdout` and `redirect_stderr`.
279+
# https://github.com/python/typeshed/issues/14903
280+
@type_check_only
281+
class _SupportsRedirect(Protocol):
282+
def write(self, s: str, /) -> int: ...
283+
def flush(self) -> None: ...
284+
285+
_SupportsRedirectT = TypeVar("_SupportsRedirectT", bound=_SupportsRedirect | None)
286+
287+
class _RedirectStream(AbstractContextManager[_SupportsRedirectT, None]):
288+
def __init__(self, new_target: _SupportsRedirectT) -> None: ...
280289
def __exit__(
281290
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
282291
) -> None: ...
283292

284-
class redirect_stdout(_RedirectStream[_T_io]):
293+
class redirect_stdout(_RedirectStream[_SupportsRedirectT]):
285294
"""Context manager for temporarily redirecting stdout to another file.
286295
287296
# How to send help() to stderr
@@ -294,7 +303,7 @@ class redirect_stdout(_RedirectStream[_T_io]):
294303
help(pow)
295304
"""
296305

297-
class redirect_stderr(_RedirectStream[_T_io]):
306+
class redirect_stderr(_RedirectStream[_SupportsRedirectT]):
298307
"""Context manager for temporarily redirecting stderr to another file."""
299308

300309
class _BaseExitStack(Generic[_ExitT_co]):

crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,8 @@ if sys.version_info >= (3, 11):
623623
the module is the last module in case of a multi-module name
624624
"""
625625

626+
def show_flag_values(value: int) -> list[int]: ...
627+
626628
if sys.version_info >= (3, 12):
627629
# The body of the class is the same, but the base classes are different.
628630
class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases

crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,9 @@ environ: _Environ[str]
752752
if sys.platform != "win32":
753753
environb: _Environ[bytes]
754754

755+
if sys.version_info >= (3, 14):
756+
def reload_environ() -> None: ...
757+
755758
if sys.version_info >= (3, 11) or sys.platform != "win32":
756759
EX_OK: Final[int]
757760

crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,21 @@ def _getframe(depth: int = 0, /) -> FrameType:
578578
only.
579579
"""
580580

581+
# documented -- see https://docs.python.org/3/library/sys.html#sys._current_exceptions
582+
if sys.version_info >= (3, 12):
583+
def _current_exceptions() -> dict[int, BaseException | None]:
584+
"""Return a dict mapping each thread's identifier to its current raised exception.
585+
586+
This function should be used for specialized purposes only.
587+
"""
588+
589+
else:
590+
def _current_exceptions() -> dict[int, OptExcInfo]:
591+
"""Return a dict mapping each thread's identifier to its current raised exception.
592+
593+
This function should be used for specialized purposes only.
594+
"""
595+
581596
if sys.version_info >= (3, 12):
582597
def _getframemodulename(depth: int = 0) -> str | None:
583598
"""Return the name of the module for a calling frame.
@@ -627,6 +642,9 @@ def exit(status: _ExitCode = None, /) -> NoReturn:
627642
exit status will be one (i.e., failure).
628643
"""
629644

645+
if sys.platform == "android": # noqa: Y008
646+
def getandroidapilevel() -> int: ...
647+
630648
def getallocatedblocks() -> int:
631649
"""Return the number of memory blocks currently allocated."""
632650

@@ -949,3 +967,9 @@ if sys.version_info >= (3, 14):
949967
script (str|bytes): The path to a file containing
950968
the Python code to be executed.
951969
"""
970+
971+
def _is_immortal(op: object, /) -> bool:
972+
"""Return True if the given object is "immortal" per PEP 683.
973+
974+
This function should be used for specialized purposes only.
975+
"""

crates/ty_vendored/vendor/typeshed/stdlib/sysconfig.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
from typing import IO, Any, Literal, overload
5-
from typing_extensions import deprecated
5+
from typing_extensions import LiteralString, deprecated
66

77
__all__ = [
88
"get_config_h_filename",
@@ -47,8 +47,10 @@ def get_scheme_names() -> tuple[str, ...]:
4747
"""Return a tuple containing the schemes names."""
4848

4949
if sys.version_info >= (3, 10):
50-
def get_default_scheme() -> str: ...
51-
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> str: ...
50+
def get_default_scheme() -> LiteralString: ...
51+
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> LiteralString: ...
52+
# Documented -- see https://docs.python.org/3/library/sysconfig.html#sysconfig._get_preferred_schemes
53+
def _get_preferred_schemes() -> dict[Literal["prefix", "home", "user"], LiteralString]: ...
5254

5355
def get_path_names() -> tuple[str, ...]:
5456
"""Return a tuple containing the paths names."""

crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,17 +1721,22 @@ class Wm:
17211721
if sys.platform == "darwin":
17221722
@overload
17231723
def wm_attributes(self, option: Literal["-modified"], /) -> bool:
1724-
"""Return or sets platform specific attributes.
1724+
"""This subcommand returns or sets platform specific attributes
17251725
1726-
When called with a single argument return_python_dict=True,
1727-
return a dict of the platform specific attributes and their values.
1728-
When called without arguments or with a single argument
1729-
return_python_dict=False, return a tuple containing intermixed
1730-
attribute names with the minus prefix and their values.
1726+
The first form returns a list of the platform specific flags and
1727+
their values. The second form returns the value for the specific
1728+
option. The third form sets one or more of the values. The values
1729+
are as follows:
17311730
1732-
When called with a single string value, return the value for the
1733-
specific option. When called with keyword arguments, set the
1734-
corresponding attributes.
1731+
On Windows, -disabled gets or sets whether the window is in a
1732+
disabled state. -toolwindow gets or sets the style of the window
1733+
to toolwindow (as defined in the MSDN). -topmost gets or sets
1734+
whether this is a topmost window (displays above all other
1735+
windows).
1736+
1737+
On Macintosh, XXXXX
1738+
1739+
On Unix, there are currently no special attribute values.
17351740
"""
17361741

17371742
@overload
@@ -1803,20 +1808,7 @@ class Wm:
18031808
def wm_attributes(self, option: Literal["topmost"], /) -> bool: ...
18041809
if sys.platform == "darwin":
18051810
@overload
1806-
def wm_attributes(self, option: Literal["modified"], /) -> bool:
1807-
"""Return or sets platform specific attributes.
1808-
1809-
When called with a single argument return_python_dict=True,
1810-
return a dict of the platform specific attributes and their values.
1811-
When called without arguments or with a single argument
1812-
return_python_dict=False, return a tuple containing intermixed
1813-
attribute names with the minus prefix and their values.
1814-
1815-
When called with a single string value, return the value for the
1816-
specific option. When called with keyword arguments, set the
1817-
corresponding attributes.
1818-
"""
1819-
1811+
def wm_attributes(self, option: Literal["modified"], /) -> bool: ...
18201812
@overload
18211813
def wm_attributes(self, option: Literal["notify"], /) -> bool: ...
18221814
@overload
@@ -1876,17 +1868,22 @@ class Wm:
18761868
if sys.platform == "darwin":
18771869
@overload
18781870
def wm_attributes(self, option: Literal["-modified"], value: bool, /) -> Literal[""]:
1879-
"""Return or sets platform specific attributes.
1871+
"""This subcommand returns or sets platform specific attributes
18801872
1881-
When called with a single argument return_python_dict=True,
1882-
return a dict of the platform specific attributes and their values.
1883-
When called without arguments or with a single argument
1884-
return_python_dict=False, return a tuple containing intermixed
1885-
attribute names with the minus prefix and their values.
1873+
The first form returns a list of the platform specific flags and
1874+
their values. The second form returns the value for the specific
1875+
option. The third form sets one or more of the values. The values
1876+
are as follows:
18861877
1887-
When called with a single string value, return the value for the
1888-
specific option. When called with keyword arguments, set the
1889-
corresponding attributes.
1878+
On Windows, -disabled gets or sets whether the window is in a
1879+
disabled state. -toolwindow gets or sets the style of the window
1880+
to toolwindow (as defined in the MSDN). -topmost gets or sets
1881+
whether this is a topmost window (displays above all other
1882+
windows).
1883+
1884+
On Macintosh, XXXXX
1885+
1886+
On Unix, there are currently no special attribute values.
18901887
"""
18911888

18921889
@overload
@@ -1950,19 +1947,7 @@ class Wm:
19501947
titlepath: str = ...,
19511948
topmost: bool = ...,
19521949
transparent: bool = ...,
1953-
) -> None:
1954-
"""Return or sets platform specific attributes.
1955-
1956-
When called with a single argument return_python_dict=True,
1957-
return a dict of the platform specific attributes and their values.
1958-
When called without arguments or with a single argument
1959-
return_python_dict=False, return a tuple containing intermixed
1960-
attribute names with the minus prefix and their values.
1961-
1962-
When called with a single string value, return the value for the
1963-
specific option. When called with keyword arguments, set the
1964-
corresponding attributes.
1965-
"""
1950+
) -> None: ...
19661951
elif sys.platform == "win32":
19671952
@overload
19681953
def wm_attributes(

0 commit comments

Comments
 (0)