Skip to content

Commit 98d7930

Browse files
Sync typeshed (#20157)
Source commit: python/typeshed@bf72147
1 parent d6e9c31 commit 98d7930

File tree

9 files changed

+47
-16
lines changed

9 files changed

+47
-16
lines changed

mypy/typeshed/stdlib/builtins.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,6 +1960,10 @@ class BaseException:
19601960
def __new__(cls, *args: Any, **kwds: Any) -> Self: ...
19611961
def __setstate__(self, state: dict[str, Any] | None, /) -> None: ...
19621962
def with_traceback(self, tb: TracebackType | None, /) -> Self: ...
1963+
# Necessary for security-focused static analyzers (e.g, pysa)
1964+
# See https://github.com/python/typeshed/pull/14900
1965+
def __str__(self) -> str: ... # noqa: Y029
1966+
def __repr__(self) -> str: ... # noqa: Y029
19631967
if sys.version_info >= (3, 11):
19641968
# only present after add_note() is called
19651969
__notes__: list[str]

mypy/typeshed/stdlib/cmath.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def exp(z: _C, /) -> complex: ...
2323
def isclose(a: _C, b: _C, *, rel_tol: SupportsFloat = 1e-09, abs_tol: SupportsFloat = 0.0) -> bool: ...
2424
def isinf(z: _C, /) -> bool: ...
2525
def isnan(z: _C, /) -> bool: ...
26-
def log(x: _C, base: _C = ..., /) -> complex: ...
26+
def log(z: _C, base: _C = ..., /) -> complex: ...
2727
def log10(z: _C, /) -> complex: ...
2828
def phase(z: _C, /) -> float: ...
2929
def polar(z: _C, /) -> tuple[float, float]: ...

mypy/typeshed/stdlib/contextlib.pyi

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

1010
__all__ = [
@@ -30,7 +30,6 @@ if sys.version_info >= (3, 11):
3030

3131
_T = TypeVar("_T")
3232
_T_co = TypeVar("_T_co", covariant=True)
33-
_T_io = TypeVar("_T_io", bound=IO[str] | None)
3433
_ExitT_co = TypeVar("_ExitT_co", covariant=True, bound=bool | None, default=bool | None)
3534
_F = TypeVar("_F", bound=Callable[..., Any])
3635
_G_co = TypeVar("_G_co", bound=Generator[Any, Any, Any] | AsyncGenerator[Any, Any], covariant=True)
@@ -141,14 +140,24 @@ class suppress(AbstractContextManager[None, bool]):
141140
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
142141
) -> bool: ...
143142

144-
class _RedirectStream(AbstractContextManager[_T_io, None]):
145-
def __init__(self, new_target: _T_io) -> None: ...
143+
# This is trying to describe what is needed for (most?) uses
144+
# of `redirect_stdout` and `redirect_stderr`.
145+
# https://github.com/python/typeshed/issues/14903
146+
@type_check_only
147+
class _SupportsRedirect(Protocol):
148+
def write(self, s: str, /) -> int: ...
149+
def flush(self) -> None: ...
150+
151+
_SupportsRedirectT = TypeVar("_SupportsRedirectT", bound=_SupportsRedirect | None)
152+
153+
class _RedirectStream(AbstractContextManager[_SupportsRedirectT, None]):
154+
def __init__(self, new_target: _SupportsRedirectT) -> None: ...
146155
def __exit__(
147156
self, exctype: type[BaseException] | None, excinst: BaseException | None, exctb: TracebackType | None
148157
) -> None: ...
149158

150-
class redirect_stdout(_RedirectStream[_T_io]): ...
151-
class redirect_stderr(_RedirectStream[_T_io]): ...
159+
class redirect_stdout(_RedirectStream[_SupportsRedirectT]): ...
160+
class redirect_stderr(_RedirectStream[_SupportsRedirectT]): ...
152161

153162
class _BaseExitStack(Generic[_ExitT_co]):
154163
def enter_context(self, cm: AbstractContextManager[_T, _ExitT_co]) -> _T: ...

mypy/typeshed/stdlib/enum.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ if sys.version_info >= (3, 11):
309309
def global_enum(cls: _EnumerationT, update_str: bool = False) -> _EnumerationT: ...
310310
def global_enum_repr(self: Enum) -> str: ...
311311
def global_flag_repr(self: Flag) -> str: ...
312+
def show_flag_values(value: int) -> list[int]: ...
312313

313314
if sys.version_info >= (3, 12):
314315
# The body of the class is the same, but the base classes are different.

mypy/typeshed/stdlib/os/__init__.pyi

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

732+
if sys.version_info >= (3, 14):
733+
def reload_environ() -> None: ...
734+
732735
if sys.version_info >= (3, 11) or sys.platform != "win32":
733736
EX_OK: Final[int]
734737

mypy/typeshed/stdlib/sys/__init__.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,13 @@ else:
354354
def _current_frames() -> dict[int, FrameType]: ...
355355
def _getframe(depth: int = 0, /) -> FrameType: ...
356356

357+
# documented -- see https://docs.python.org/3/library/sys.html#sys._current_exceptions
358+
if sys.version_info >= (3, 12):
359+
def _current_exceptions() -> dict[int, BaseException | None]: ...
360+
361+
else:
362+
def _current_exceptions() -> dict[int, OptExcInfo]: ...
363+
357364
if sys.version_info >= (3, 12):
358365
def _getframemodulename(depth: int = 0) -> str | None: ...
359366

@@ -366,6 +373,10 @@ if sys.version_info >= (3, 11):
366373
def exception() -> BaseException | None: ...
367374

368375
def exit(status: _ExitCode = None, /) -> NoReturn: ...
376+
377+
if sys.platform == "android": # noqa: Y008
378+
def getandroidapilevel() -> int: ...
379+
369380
def getallocatedblocks() -> int: ...
370381
def getdefaultencoding() -> str: ...
371382

@@ -501,3 +512,4 @@ if sys.version_info >= (3, 12):
501512
if sys.version_info >= (3, 14):
502513
def is_remote_debug_enabled() -> bool: ...
503514
def remote_exec(pid: int, script: StrOrBytesPath) -> None: ...
515+
def _is_immortal(op: object, /) -> bool: ...

mypy/typeshed/stdlib/sysconfig.pyi

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from typing import IO, Any, Literal, overload
3-
from typing_extensions import deprecated
3+
from typing_extensions import LiteralString, deprecated
44

55
__all__ = [
66
"get_config_h_filename",
@@ -28,8 +28,10 @@ def get_config_vars(arg: str, /, *args: str) -> list[Any]: ...
2828
def get_scheme_names() -> tuple[str, ...]: ...
2929

3030
if sys.version_info >= (3, 10):
31-
def get_default_scheme() -> str: ...
32-
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> str: ...
31+
def get_default_scheme() -> LiteralString: ...
32+
def get_preferred_scheme(key: Literal["prefix", "home", "user"]) -> LiteralString: ...
33+
# Documented -- see https://docs.python.org/3/library/sysconfig.html#sysconfig._get_preferred_schemes
34+
def _get_preferred_schemes() -> dict[Literal["prefix", "home", "user"], LiteralString]: ...
3335

3436
def get_path_names() -> tuple[str, ...]: ...
3537
def get_path(name: str, scheme: str = ..., vars: dict[str, Any] | None = None, expand: bool = True) -> str: ...

mypy/typeshed/stdlib/turtle.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class TurtleScreen(TurtleScreenBase):
266266
def window_height(self) -> int: ...
267267
def getcanvas(self) -> Canvas: ...
268268
def getshapes(self) -> list[str]: ...
269-
def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None: ...
269+
def onclick(self, fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ...
270270
def onkey(self, fun: Callable[[], object], key: str) -> None: ...
271271
def listen(self, xdummy: float | None = None, ydummy: float | None = None) -> None: ...
272272
def ontimer(self, fun: Callable[[], object], t: int = 0) -> None: ...
@@ -561,7 +561,7 @@ def window_width() -> int: ...
561561
def window_height() -> int: ...
562562
def getcanvas() -> Canvas: ...
563563
def getshapes() -> list[str]: ...
564-
def onclick(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None: ...
564+
def onclick(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ...
565565
def onkey(fun: Callable[[], object], key: str) -> None: ...
566566
def listen(xdummy: float | None = None, ydummy: float | None = None) -> None: ...
567567
def ontimer(fun: Callable[[], object], t: int = 0) -> None: ...
@@ -776,8 +776,8 @@ def getturtle() -> Turtle: ...
776776

777777
getpen = getturtle
778778

779-
def onrelease(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None: ...
780-
def ondrag(fun: Callable[[float, float], object], btn: int = 1, add: Any | None = None) -> None: ...
779+
def onrelease(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ...
780+
def ondrag(fun: Callable[[float, float], object], btn: int = 1, add: bool | None = None) -> None: ...
781781
def undo() -> None: ...
782782

783783
turtlesize = shapesize

mypy/typeshed/stdlib/zlib.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Z_RLE: Final = 3
2626
Z_SYNC_FLUSH: Final = 2
2727
Z_TREES: Final = 6
2828

29-
if sys.version_info >= (3, 14) and sys.platform == "win32":
30-
# Available when zlib was built with zlib-ng, usually only on Windows
29+
if sys.version_info >= (3, 14):
30+
# Available when zlib was built with zlib-ng
3131
ZLIBNG_VERSION: Final[str]
3232

3333
class error(Exception): ...

0 commit comments

Comments
 (0)