From efe4432fdf101e0cd58ce7318b4954a5d5846cff Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 5 Nov 2026 00:04:40 +0100 Subject: [PATCH 01/12] Sync typeshed Source commit: https://github.com/python/typeshed/commit/dac770db25471e9d246f861fc25045398aeacd62 --- mypy/typeshed/stdlib/VERSIONS | 1 + mypy/typeshed/stdlib/__future__.pyi | 2 +- mypy/typeshed/stdlib/_asyncio.pyi | 4 +- mypy/typeshed/stdlib/_colorize.pyi | 418 ++++++++++++++++++ mypy/typeshed/stdlib/_ctypes.pyi | 7 +- mypy/typeshed/stdlib/_io.pyi | 14 +- mypy/typeshed/stdlib/_operator.pyi | 59 ++- mypy/typeshed/stdlib/_remote_debugging.pyi | 3 + mypy/typeshed/stdlib/_socket.pyi | 2 + mypy/typeshed/stdlib/argparse.pyi | 8 +- mypy/typeshed/stdlib/builtins.pyi | 175 +++++++- mypy/typeshed/stdlib/codecs.pyi | 2 +- mypy/typeshed/stdlib/contextlib.pyi | 15 +- mypy/typeshed/stdlib/csv.pyi | 4 +- mypy/typeshed/stdlib/datetime.pyi | 213 +++++++-- mypy/typeshed/stdlib/dis.pyi | 4 +- .../stdlib/email/_header_value_parser.pyi | 8 + mypy/typeshed/stdlib/email/base64mime.pyi | 4 +- mypy/typeshed/stdlib/encodings/cp037.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1006.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1026.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1125.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1140.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1250.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1251.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1252.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1253.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1254.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1255.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1256.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1257.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp1258.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp273.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp424.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp437.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp500.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp720.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp737.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp775.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp850.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp852.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp855.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp856.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp857.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp858.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp860.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp861.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp862.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp863.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp864.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp865.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp866.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp869.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp874.pyi | 2 +- mypy/typeshed/stdlib/encodings/cp875.pyi | 2 +- mypy/typeshed/stdlib/encodings/hp_roman8.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_1.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_10.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_11.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_13.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_14.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_15.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_16.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_2.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_3.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_4.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_5.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_6.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_7.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_8.pyi | 2 +- mypy/typeshed/stdlib/encodings/iso8859_9.pyi | 2 +- mypy/typeshed/stdlib/encodings/koi8_r.pyi | 2 +- mypy/typeshed/stdlib/encodings/koi8_t.pyi | 2 +- mypy/typeshed/stdlib/encodings/koi8_u.pyi | 2 +- mypy/typeshed/stdlib/encodings/kz1048.pyi | 2 +- mypy/typeshed/stdlib/encodings/mac_arabic.pyi | 2 +- .../stdlib/encodings/mac_croatian.pyi | 2 +- .../stdlib/encodings/mac_cyrillic.pyi | 2 +- mypy/typeshed/stdlib/encodings/mac_farsi.pyi | 2 +- mypy/typeshed/stdlib/encodings/mac_greek.pyi | 2 +- .../typeshed/stdlib/encodings/mac_iceland.pyi | 2 +- mypy/typeshed/stdlib/encodings/mac_latin2.pyi | 2 +- mypy/typeshed/stdlib/encodings/mac_roman.pyi | 2 +- .../stdlib/encodings/mac_romanian.pyi | 2 +- .../typeshed/stdlib/encodings/mac_turkish.pyi | 2 +- mypy/typeshed/stdlib/encodings/palmos.pyi | 2 +- mypy/typeshed/stdlib/encodings/ptcp154.pyi | 2 +- mypy/typeshed/stdlib/encodings/punycode.pyi | 5 +- mypy/typeshed/stdlib/encodings/tis_620.pyi | 2 +- mypy/typeshed/stdlib/fileinput.pyi | 6 +- mypy/typeshed/stdlib/functools.pyi | 15 +- mypy/typeshed/stdlib/inspect.pyi | 4 +- mypy/typeshed/stdlib/itertools.pyi | 40 +- .../stdlib/multiprocessing/context.pyi | 7 +- .../stdlib/multiprocessing/managers.pyi | 2 +- mypy/typeshed/stdlib/multiprocessing/pool.pyi | 4 +- mypy/typeshed/stdlib/os/__init__.pyi | 22 + mypy/typeshed/stdlib/posix.pyi | 5 + mypy/typeshed/stdlib/re.pyi | 4 + mypy/typeshed/stdlib/socket.pyi | 9 +- mypy/typeshed/stdlib/sqlite3/__init__.pyi | 2 +- mypy/typeshed/stdlib/time.pyi | 6 +- mypy/typeshed/stdlib/tkinter/filedialog.pyi | 84 ++-- mypy/typeshed/stdlib/tkinter/ttk.pyi | 16 +- mypy/typeshed/stdlib/typing.pyi | 10 +- 105 files changed, 1082 insertions(+), 242 deletions(-) create mode 100644 mypy/typeshed/stdlib/_colorize.pyi diff --git a/mypy/typeshed/stdlib/VERSIONS b/mypy/typeshed/stdlib/VERSIONS index 96eb98131db6..4d110df06657 100644 --- a/mypy/typeshed/stdlib/VERSIONS +++ b/mypy/typeshed/stdlib/VERSIONS @@ -26,6 +26,7 @@ _blake2: 3.6- _bz2: 3.3- _codecs: 3.0- _collections_abc: 3.3- +_colorize: 3.13- _compat_pickle: 3.1- _compression: 3.5-3.13 _contextvars: 3.7- diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi index a90cf1eddab7..aa445d22bd20 100644 --- a/mypy/typeshed/stdlib/__future__.pyi +++ b/mypy/typeshed/stdlib/__future__.pyi @@ -1,4 +1,4 @@ -from typing_extensions import TypeAlias +from typing import TypeAlias _VersionInfo: TypeAlias = tuple[int, int, int, str, int] diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi index 386a96f38abd..641c152d985b 100644 --- a/mypy/typeshed/stdlib/_asyncio.pyi +++ b/mypy/typeshed/stdlib/_asyncio.pyi @@ -1,6 +1,6 @@ import sys from asyncio.events import AbstractEventLoop -from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable +from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType, GenericAlias from typing import Any, Literal, TextIO, TypeAlias, TypeVar @@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None @disjoint_base -class Future(Awaitable[_T], Iterable[_T]): +class Future(Awaitable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/_colorize.pyi b/mypy/typeshed/stdlib/_colorize.pyi new file mode 100644 index 000000000000..56914f97223d --- /dev/null +++ b/mypy/typeshed/stdlib/_colorize.pyi @@ -0,0 +1,418 @@ +import builtins +import sys +from collections.abc import Iterator, Mapping +from dataclasses import dataclass +from typing import Any, Final, Literal, TypeAlias +from typing_extensions import Self + +# A protocol with an optional `fileno(self) -> int: ...` member. +_MaySupportFileno: TypeAlias = Any + +COLORIZE: bool + +if sys.version_info >= (3, 14): + _theme: Theme # undocumented + +if sys.version_info >= (3, 15): + BackgroundStyle: TypeAlias = Literal["dark", "light"] + +class ANSIColors: + RESET: Final = "\x1b[0m" + BLACK: Final = "\x1b[30m" + BLUE: Final = "\x1b[34m" + CYAN: Final = "\x1b[36m" + GREEN: Final = "\x1b[32m" + if sys.version_info >= (3, 14): + GREY: Final = "\x1b[90m" + MAGENTA: Final = "\x1b[35m" + RED: Final = "\x1b[31m" + WHITE: Final = "\x1b[37m" + YELLOW: Final = "\x1b[33m" + + if sys.version_info >= (3, 14): + BOLD: Final = "\x1b[1m" + BOLD_BLACK: Final = "\x1b[1;30m" + BOLD_BLUE: Final = "\x1b[1;34m" + BOLD_CYAN: Final = "\x1b[1;36m" + BOLD_GREEN: Final = "\x1b[1;32m" + BOLD_MAGENTA: Final = "\x1b[1;35m" + BOLD_RED: Final = "\x1b[1;31m" + BOLD_WHITE: Final = "\x1b[1;37m" + BOLD_YELLOW: Final = "\x1b[1;33m" + + INTENSE_BLACK: Final = "\x1b[90m" + INTENSE_BLUE: Final = "\x1b[94m" + INTENSE_CYAN: Final = "\x1b[96m" + INTENSE_GREEN: Final = "\x1b[92m" + INTENSE_MAGENTA: Final = "\x1b[95m" + INTENSE_RED: Final = "\x1b[91m" + INTENSE_WHITE: Final = "\x1b[97m" + INTENSE_YELLOW: Final = "\x1b[93m" + + BACKGROUND_BLACK: Final = "\x1b[40m" + BACKGROUND_BLUE: Final = "\x1b[44m" + BACKGROUND_CYAN: Final = "\x1b[46m" + BACKGROUND_GREEN: Final = "\x1b[42m" + BACKGROUND_MAGENTA: Final = "\x1b[45m" + BACKGROUND_RED: Final = "\x1b[41m" + BACKGROUND_WHITE: Final = "\x1b[47m" + BACKGROUND_YELLOW: Final = "\x1b[43m" + + INTENSE_BACKGROUND_BLACK: Final = "\x1b[100m" + INTENSE_BACKGROUND_BLUE: Final = "\x1b[104m" + INTENSE_BACKGROUND_CYAN: Final = "\x1b[106m" + INTENSE_BACKGROUND_GREEN: Final = "\x1b[102m" + INTENSE_BACKGROUND_MAGENTA: Final = "\x1b[105m" + INTENSE_BACKGROUND_RED: Final = "\x1b[101m" + INTENSE_BACKGROUND_WHITE: Final = "\x1b[107m" + INTENSE_BACKGROUND_YELLOW: Final = "\x1b[103m" + +if sys.version_info >= (3, 14): + ColorCodes: Final[set[str]] + +NoColors: Final[ANSIColors] + +if sys.version_info >= (3, 15): + class CursesColors: + BLACK: Final = 0 + RED: Final = 1 + GREEN: Final = 2 + YELLOW: Final = 3 + BLUE: Final = 4 + MAGENTA: Final = 5 + CYAN: Final = 6 + WHITE: Final = 7 + DEFAULT: Final = -1 + +if sys.version_info >= (3, 14): + class ThemeSection(Mapping[str, str]): + def __post_init__(self) -> None: ... + def copy_with(self, **kwargs: str) -> Self: ... + @classmethod + def no_colors(cls) -> Self: ... + def __getitem__(self, key: str) -> str: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[str]: ... + +if sys.version_info >= (3, 15): + @dataclass(frozen=True, kw_only=True) + class Argparse(ThemeSection): + usage: str = ... + prog: str = ... + prog_extra: str = ... + heading: str = ... + summary_long_option: str = ... + summary_short_option: str = ... + summary_label: str = ... + summary_action: str = ... + long_option: str = ... + short_option: str = ... + label: str = ... + action: str = ... + default: str = ... + interpolated_value: str = ... + reset: str = ... + error: str = ... + warning: str = ... + message: str = ... + + @dataclass(frozen=True, kw_only=True) + class Ast(ThemeSection): + node: str = ... + field: str = ... + attribute: str = ... + string: str = ... + number: str = ... + keyword: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Calendar(ThemeSection): + header: str = ... + highlight: str = ... + weekday: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Difflib(ThemeSection): + added: str = ... + context: str = ... + header: str = ... + hunk: str = ... + removed: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class FancyCompleter(ThemeSection): + function: builtins.str = ... + builtin_function_or_method: builtins.str = ... + method: builtins.str = ... + method_wrapper: builtins.str = ... + wrapper_descriptor: builtins.str = ... + method_descriptor: builtins.str = ... + int: builtins.str = ... + float: builtins.str = ... + complex: builtins.str = ... + bool: builtins.str = ... + type: builtins.str = ... + module: builtins.str = ... + NoneType: builtins.str = ... + bytes: builtins.str = ... + str: builtins.str = ... + + @dataclass(frozen=True, kw_only=True) + class HttpServer(ThemeSection): + error: str = ... + path: str = ... + serving: str = ... + size: str = ... + status_informational: str = ... + status_ok: str = ... + status_redirect: str = ... + status_client_error: str = ... + status_server_error: str = ... + timestamp: str = ... + url: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class LiveProfiler(ThemeSection): + title_fg: int = ... + title_bg: int = ... + pid_fg: int = ... + uptime_fg: int = ... + time_fg: int = ... + interval_fg: int = ... + thread_all_fg: int = ... + thread_single_fg: int = ... + bar_good_fg: int = ... + bar_bad_fg: int = ... + on_gil_fg: int = ... + off_gil_fg: int = ... + waiting_gil_fg: int = ... + gc_fg: int = ... + func_total_fg: int = ... + func_exec_fg: int = ... + func_stack_fg: int = ... + func_shown_fg: int = ... + sorted_header_fg: int = ... + sorted_header_bg: int = ... + normal_header_fg: int = ... + normal_header_bg: int = ... + samples_fg: int = ... + file_fg: int = ... + func_fg: int = ... + trend_up_fg: int = ... + trend_down_fg: int = ... + medal_gold_fg: int = ... + medal_silver_fg: int = ... + medal_bronze_fg: int = ... + background_style: BackgroundStyle = "dark" + + LiveProfilerLight: Final[LiveProfiler] + + @dataclass(frozen=True, kw_only=True) + class ProfilerDump(ThemeSection): + header: str = ... + interpreter: str = ... + thread: str = ... + status: str = ... + frame_index: str = ... + frame: str = ... + filename: str = ... + line_no: str = ... + source: str = ... + source_highlight: str = ... + opcode: str = ... + warning: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Pickletools(ThemeSection): + annotation: str = ... + arg_number: str = ... + arg_string: str = ... + mark: str = ... + op_call: str = ... + op_container: str = ... + op_memo: str = ... + op_meta: str = ... + op_stack: str = ... + opcode_code: str = ... + position: str = ... + proto: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Syntax(ThemeSection): + prompt: str = ... + keyword: str = ... + keyword_constant: str = ... + builtin: str = ... + comment: str = ... + string: str = ... + number: str = ... + op: str = ... + definition: str = ... + soft_keyword: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Timeit(ThemeSection): + timing: str = ... + best: str = ... + per_loop: str = ... + punctuation: str = ... + warning: str = ... + warning_worst: str = ... + warning_best: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Tokenize(ThemeSection): + whitespace: str = ... + error: str = ... + position: str = ... + delimiter: str = ... + + @dataclass(frozen=True, kw_only=True) + class Traceback(ThemeSection): + type: str = ... + message: str = ... + note: str = ... + filename: str = ... + line_no: str = ... + frame: str = ... + error_highlight: str = ... + error_range: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Unittest(ThemeSection): + passed: str = ... + warn: str = ... + fail: str = ... + fail_info: str = ... + reset: str = ... + + @dataclass(frozen=True, kw_only=True) + class Theme: + argparse: Argparse = ... + ast: Ast = ... + calendar: Calendar = ... + difflib: Difflib = ... + fancycompleter: FancyCompleter = ... + http_server: HttpServer = ... + live_profiler: LiveProfiler = ... + pickletools: Pickletools = ... + profiler_dump: ProfilerDump = ... + syntax: Syntax = ... + timeit: Timeit = ... + tokenize: Tokenize = ... + traceback: Traceback = ... + unittest: Unittest = ... + def copy_with( + self, + *, + argparse: Argparse | None = None, + ast: Ast | None = None, + calendar: Calendar | None = None, + difflib: Difflib | None = None, + fancycompleter: FancyCompleter | None = None, + http_server: HttpServer | None = None, + live_profiler: LiveProfiler | None = None, + pickletools: Pickletools | None = None, + profiler_dump: ProfilerDump | None = None, + syntax: Syntax | None = None, + timeit: Timeit | None = None, + tokenize: Tokenize | None = None, + traceback: Traceback | None = None, + unittest: Unittest | None = None, + ) -> Self: ... + @classmethod + def no_colors(cls) -> Self: ... + +elif sys.version_info >= (3, 14): + @dataclass(frozen=True, kw_only=True) + class Argparse(ThemeSection): + usage: str = ... + prog: str = ... + prog_extra: str = ... + heading: str = ... + summary_long_option: str = ... + summary_short_option: str = ... + summary_label: str = ... + summary_action: str = ... + long_option: str = ... + short_option: str = ... + label: str = ... + action: str = ... + reset: str = ... + + @dataclass(frozen=True) + class Syntax(ThemeSection): + prompt: str = ... + keyword: str = ... + keyword_constant: str = ... + builtin: str = ... + comment: str = ... + string: str = ... + number: str = ... + op: str = ... + definition: str = ... + soft_keyword: str = ... + reset: str = ... + + @dataclass(frozen=True) + class Traceback(ThemeSection): + type: str = ... + message: str = ... + filename: str = ... + line_no: str = ... + frame: str = ... + error_highlight: str = ... + error_range: str = ... + reset: str = ... + + @dataclass(frozen=True) + class Unittest(ThemeSection): + passed: str = ... + warn: str = ... + fail: str = ... + fail_info: str = ... + reset: str = ... + + @dataclass(frozen=True) + class Theme: + argparse: Argparse = ... + syntax: Syntax = ... + traceback: Traceback = ... + unittest: Unittest = ... + def copy_with( + self, + *, + argparse: Argparse | None = None, + syntax: Syntax | None = None, + traceback: Traceback | None = None, + unittest: Unittest | None = None, + ) -> Self: ... + @classmethod + def no_colors(cls) -> Self: ... + +def get_colors(colorize: bool = False, *, file: _MaySupportFileno | None = None) -> ANSIColors: ... + +if sys.version_info >= (3, 14): + def decolor(text: str) -> str: ... + +def can_colorize(*, file: _MaySupportFileno | None = None) -> bool: ... + +if sys.version_info >= (3, 14): + default_theme: Final[Theme] + theme_no_color: Final[Theme] + if sys.version_info >= (3, 15): + light_profiler_theme: Final[Theme] + + def get_theme( + *, tty_file: _MaySupportFileno | None = None, force_color: bool = False, force_no_color: bool = False + ) -> Theme: ... + def set_theme(t: Theme) -> None: ... diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi index 45cf0e9bad57..83ac60fd0d42 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi @@ -324,7 +324,12 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @_type_.setter def _type_(self, value: type[_CT]) -> None: ... - raw: bytes # Note: only available if _CT == c_char + # Note: only available if _CT == c_char + @property + def raw(self) -> bytes: ... + @raw.setter + def raw(self, value: ReadableBuffer) -> None: ... + value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise # TODO: These methods cannot be annotated correctly at the moment. # All of these "Any"s stand for the array's element type, but it's not possible to use _CT diff --git a/mypy/typeshed/stdlib/_io.pyi b/mypy/typeshed/stdlib/_io.pyi index 5e216123be98..e62fc51d0f46 100644 --- a/mypy/typeshed/stdlib/_io.pyi +++ b/mypy/typeshed/stdlib/_io.pyi @@ -2,7 +2,7 @@ import builtins import codecs import sys from _typeshed import FileDescriptorOrPath, MaybeNone, ReadableBuffer, WriteableBuffer -from collections.abc import Callable, Iterable, Iterator +from collections.abc import Iterable, Iterator from io import BufferedIOBase, RawIOBase, TextIOBase, UnsupportedOperation as UnsupportedOperation from os import _Opener from types import TracebackType @@ -36,14 +36,16 @@ if sys.version_info >= (3, 12): def flush(self) -> None: ... def isatty(self) -> bool: ... def readable(self) -> bool: ... - read: Callable[..., Any] + # Abstract method that doesn't exist at runtime, the exact return type depends on the sub-class + def read(self, size: int = ..., /) -> Any: ... def readlines(self, hint: int = -1, /) -> list[bytes]: ... def seek(self, offset: int, whence: int = 0, /) -> int: ... def seekable(self) -> bool: ... def tell(self) -> int: ... def truncate(self, size: int | None = None, /) -> int: ... def writable(self) -> bool: ... - write: Callable[..., Any] + # Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class + def write(self, s: Any, /) -> Any: ... def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ... def readline(self, size: int | None = -1, /) -> bytes: ... def __del__(self) -> None: ... @@ -64,14 +66,16 @@ else: def flush(self) -> None: ... def isatty(self) -> bool: ... def readable(self) -> bool: ... - read: Callable[..., Any] + # Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class + def read(self) -> Any: ... def readlines(self, hint: int = -1, /) -> list[bytes]: ... def seek(self, offset: int, whence: int = 0, /) -> int: ... def seekable(self) -> bool: ... def tell(self) -> int: ... def truncate(self, size: int | None = None, /) -> int: ... def writable(self) -> bool: ... - write: Callable[..., Any] + # Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class + def write(self, s: Any, /) -> Any: ... def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ... def readline(self, size: int | None = -1, /) -> bytes: ... def __del__(self) -> None: ... diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi index ff419842ebfc..565bb41697f1 100644 --- a/mypy/typeshed/stdlib/_operator.pyi +++ b/mypy/typeshed/stdlib/_operator.pyi @@ -1,5 +1,16 @@ import sys -from _typeshed import ReadableBuffer, SupportsGetItem +from _typeshed import ( + ReadableBuffer, + SupportsAdd, + SupportsGetItem, + SupportsMod, + SupportsMul, + SupportsRAdd, + SupportsRMod, + SupportsRMul, + SupportsRSub, + SupportsSub, +) from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller from typing import Any, ParamSpec, Protocol, SupportsAbs, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only @@ -8,6 +19,7 @@ from typing_extensions import TypeIs _R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) +_T_contra = TypeVar("_T_contra", contravariant=True) _K = TypeVar("_K") _V = TypeVar("_V") _P = ParamSpec("_P") @@ -58,24 +70,43 @@ def truth(a: object, /) -> bool: ... def is_(a: object, b: object, /) -> bool: ... def is_not(a: object, b: object, /) -> bool: ... def abs(a: SupportsAbs[_T], /) -> _T: ... -def add(a: Any, b: Any, /) -> Any: ... -def and_(a: Any, b: Any, /) -> Any: ... -def floordiv(a: Any, b: Any, /) -> Any: ... + +@overload +def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ... + +def and_(a, b, /): ... +def floordiv(a, b, /): ... def index(a: SupportsIndex, /) -> int: ... def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ... def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ... -def lshift(a: Any, b: Any, /) -> Any: ... -def mod(a: Any, b: Any, /) -> Any: ... -def mul(a: Any, b: Any, /) -> Any: ... -def matmul(a: Any, b: Any, /) -> Any: ... +def lshift(a, b, /): ... + +@overload +def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ... + +@overload +def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def mul(a: _T_contra, b: SupportsRMul[_T_contra, _T_co], /) -> _T_co: ... + +def matmul(a, b, /): ... def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ... -def or_(a: Any, b: Any, /) -> Any: ... +def or_(a, b, /): ... def pos(a: _SupportsPos[_T_co], /) -> _T_co: ... -def pow(a: Any, b: Any, /) -> Any: ... -def rshift(a: Any, b: Any, /) -> Any: ... -def sub(a: Any, b: Any, /) -> Any: ... -def truediv(a: Any, b: Any, /) -> Any: ... -def xor(a: Any, b: Any, /) -> Any: ... +def pow(a, b, /): ... +def rshift(a, b, /): ... + +@overload +def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... +@overload +def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ... + +def truediv(a, b, /): ... +def xor(a, b, /): ... def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ... def contains(a: Container[object], b: object, /) -> bool: ... def countOf(a: Iterable[object], b: object, /) -> int: ... diff --git a/mypy/typeshed/stdlib/_remote_debugging.pyi b/mypy/typeshed/stdlib/_remote_debugging.pyi index 5c150442c5e3..1e9f411dd130 100644 --- a/mypy/typeshed/stdlib/_remote_debugging.pyi +++ b/mypy/typeshed/stdlib/_remote_debugging.pyi @@ -156,6 +156,9 @@ class BinaryWriter: ) -> None: ... @property def total_samples(self) -> int: ... + # Added in Python 3.15.1. + @property + def limit_reached(self) -> bool: ... def write_sample(self, stack_frames: list[InterpreterInfo], timestamp_us: int) -> None: ... def set_stats( self, /, duration_sec: float, sample_rate: float, error_rate: float | None = None, missed_samples: float | None = None diff --git a/mypy/typeshed/stdlib/_socket.pyi b/mypy/typeshed/stdlib/_socket.pyi index 759fd8265387..40f76715e394 100644 --- a/mypy/typeshed/stdlib/_socket.pyi +++ b/mypy/typeshed/stdlib/_socket.pyi @@ -98,6 +98,8 @@ if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "lin SO_SETFIB: Final[int] if sys.platform == "linux" and sys.version_info >= (3, 13): SO_BINDTOIFINDEX: Final[int] +if sys.platform == "linux" and sys.version_info >= (3, 15): + SO_PASSRIGHTS: Final[int] SOMAXCONN: Final[int] diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index 2db7b8575744..da8141e235e0 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern -from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only from typing_extensions import Never, Self, deprecated __all__ = [ @@ -36,9 +36,7 @@ ONE_OR_MORE: Final = "+" OPTIONAL: Final = "?" PARSER: Final = "A..." REMAINDER: Final = "..." -_SUPPRESS_T = NewType("_SUPPRESS_T", str) -SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is -# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy +SUPPRESS: Final = "==SUPPRESS==" ZERO_OR_MORE: Final = "*" _UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented @@ -81,7 +79,7 @@ class _ActionsContainer: # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="], # but using this would make it hard to annotate callers that don't use a # literal argument and for subclasses to override this method. - nargs: int | str | _SUPPRESS_T | None = None, + nargs: int | str | None = None, const: Any = ..., default: Any = ..., type: _ActionType = ..., diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index d75600d1a3b8..1628f1bbf760 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -66,7 +66,7 @@ from typing import ( # noqa: Y022 # ruff: ignore[deprecated-import] # we can't import `Literal` from typing or mypy crashes: see #11247 # ruff: ignore[deprecated-import] -from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023 +from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023 if sys.version_info >= (3, 14): from _typeshed import AnnotateFunc @@ -78,6 +78,7 @@ _T_contra = TypeVar("_T_contra", contravariant=True) _R_co = TypeVar("_R_co", covariant=True) _KT = TypeVar("_KT") _VT = TypeVar("_VT") +_VT_co = TypeVar("_VT_co", covariant=True) _S = TypeVar("_S") _T1 = TypeVar("_T1") _T2 = TypeVar("_T2") @@ -484,8 +485,20 @@ class str(Sequence[str]): def __new__(cls, object: object = "") -> Self: ... @overload def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ... + + @overload + def capitalize(self: LiteralString) -> LiteralString: ... + @overload def capitalize(self) -> str: ... # type: ignore[misc] + + @overload + def casefold(self: LiteralString) -> LiteralString: ... + @overload def casefold(self) -> str: ... # type: ignore[misc] + + @overload + def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... @@ -493,9 +506,17 @@ class str(Sequence[str]): def endswith( self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... + + @overload + def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ... + @overload def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc] def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... + + @overload + def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... + @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, mapping: _FormatMapMapping, /) -> str: ... @@ -512,38 +533,119 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... + + @overload + def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ... + @overload def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc] + + @overload + def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] + + @overload + def lower(self: LiteralString) -> LiteralString: ... + @overload def lower(self) -> str: ... # type: ignore[misc] + + @overload + def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] if sys.version_info >= (3, 13): + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1 + ) -> LiteralString: ... + @overload def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc] else: + @overload + def replace( + self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, / + ) -> LiteralString: ... + @overload def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] + @overload + def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ... + @overload def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc] + + @overload + def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ... + @overload def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc] def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... + + @overload + def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... + @overload def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] + + @overload + def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... + @overload def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] + + @overload + def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... + @overload def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] + + @overload + def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... + @overload def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] + + @overload + def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ... + @overload def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc] def startswith( self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... + + @overload + def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... + @overload def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] + + @overload + def swapcase(self: LiteralString) -> LiteralString: ... + @overload def swapcase(self) -> str: ... # type: ignore[misc] + + @overload + def title(self: LiteralString) -> LiteralString: ... + @overload def title(self) -> str: ... # type: ignore[misc] def translate(self, table: _TranslateTable, /) -> str: ... + + @overload + def upper(self: LiteralString) -> LiteralString: ... + @overload def upper(self) -> str: ... # type: ignore[misc] + + @overload + def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ... + @overload def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 15): @@ -571,26 +673,51 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ... + + @overload + def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ... + @overload def __add__(self, value: str, /) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... + + @overload + def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ... + @overload def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... + + @overload + def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... + @overload def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] def __le__(self, value: str, /) -> bool: ... def __len__(self) -> int: ... def __lt__(self, value: str, /) -> bool: ... - def __mod__(self, value: Any, /) -> str: ... + + @overload + def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ... + @overload + def __mod__(self, value: object, /) -> str: ... + def __rmod__(self, value: str, /) -> str: ... + + @overload + def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... + @overload def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __ne__(self, value: object, /) -> bool: ... + + @overload + def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... + @overload def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... @@ -1252,7 +1379,7 @@ class dict(MutableMapping[_KT, _VT]): if sys.version_info >= (3, 15): @disjoint_base - class frozendict(Mapping[_KT, _VT]): + class frozendict(Mapping[_KT, _VT_co]): @overload def __new__(cls, /) -> frozendict[Any, Any]: ... @overload @@ -1270,7 +1397,7 @@ if sys.version_info >= (3, 15): cls: type[frozendict[str, _VT]], iterable: Iterable[tuple[str, _VT]], /, **kwargs: _VT ) -> frozendict[str, _VT]: ... - def copy(self) -> frozendict[_KT, _VT]: ... + def copy(self) -> frozendict[_KT, _VT_co]: ... @overload @classmethod @@ -1280,27 +1407,27 @@ if sys.version_info >= (3, 15): def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> frozendict[_T, _S]: ... @overload # type: ignore[override] - def get(self, key: _KT, default: None = None, /) -> _VT | None: ... + def get(self, key: _KT, default: None = None, /) -> _VT_co | None: ... @overload - def get(self, key: _KT, default: _VT, /) -> _VT: ... + def get(self, key: _KT, default: _VT_co, /) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant type as parameter # pyrefly: ignore [invalid-variance] @overload - def get(self, key: _KT, default: _T, /) -> _VT | _T: ... + def get(self, key: _KT, default: _T, /) -> _VT_co | _T: ... - def keys(self) -> dict_keys[_KT, _VT]: ... - def values(self) -> dict_values[_KT, _VT]: ... - def items(self) -> dict_items[_KT, _VT]: ... + def keys(self) -> dict_keys[_KT, _VT_co]: ... + def values(self) -> dict_values[_KT, _VT_co]: ... + def items(self) -> dict_items[_KT, _VT_co]: ... def __len__(self) -> int: ... - def __getitem__(self, key: _KT, /) -> _VT: ... + def __getitem__(self, key: _KT, /) -> _VT_co: ... def __reversed__(self) -> Iterator[_KT]: ... def __iter__(self) -> Iterator[_KT]: ... def __hash__(self) -> int: ... def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... - def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... + def __or__(self, value: dict[_T1, _T2] | frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT_co | _T2]: ... @overload - def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT | _T2]: ... + def __ror__(self, value: dict[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: ... @overload - def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT | _T2]: ... + def __ror__(self, value: frozendict[_T1, _T2], /) -> frozendict[_KT | _T1, _VT_co | _T2]: ... @disjoint_base class set(MutableSet[_T]): @@ -1351,10 +1478,10 @@ class set(MutableSet[_T]): @overload def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ... - def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... + def __xor__(self, value: set[_S] | frozenset[_S], /) -> set[_T | _S]: ... # type: ignore[override] def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc] - @overload + @overload # type: ignore[override] def __rxor__(self, value: set[_S], /) -> set[_T | _S]: ... @overload def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T | _S]: ... @@ -1406,9 +1533,9 @@ class frozenset(AbstractSet[_T_co]): @overload def __rsub__(self, value: frozenset[_S], /) -> frozenset[_S]: ... - def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ... + def __xor__(self, value: set[_S] | frozenset[_S], /) -> frozenset[_T_co | _S]: ... # type: ignore[override] - @overload + @overload # type: ignore[override] def __rxor__(self, value: set[_S], /) -> set[_T_co | _S]: ... @overload def __rxor__(self, value: frozenset[_S], /) -> frozenset[_T_co | _S]: ... @@ -1422,7 +1549,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class enumerate(Iterator[tuple[int, _T]]): +class enumerate(Generic[_T]): def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... @@ -1688,7 +1815,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base -class filter(Iterator[_T]): +class filter(Generic[_T]): @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload @@ -1759,7 +1886,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base -class map(Iterator[_S]): +class map(Generic[_S]): # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload @@ -2079,7 +2206,7 @@ class _SupportsReversed(Protocol[_T_co]): def __reversed__(self) -> _T_co: ... @disjoint_base -class reversed(Iterator[_T_co]): +class reversed(Generic[_T_co]): @overload def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc] @overload @@ -2145,7 +2272,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # without creating many false-positive errors (see #7578). # Instead, we special-case the most common examples of this: bool and literal integers. @overload -def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... +def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... @overload def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ... @overload @@ -2159,7 +2286,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base -class zip(Iterator[_T_co]): +class zip(Generic[_T_co]): @overload def __new__(cls, *, strict: bool = False) -> zip[Any]: ... @overload diff --git a/mypy/typeshed/stdlib/codecs.pyi b/mypy/typeshed/stdlib/codecs.pyi index ee1ab25bac47..acbf23b5992a 100644 --- a/mypy/typeshed/stdlib/codecs.pyi +++ b/mypy/typeshed/stdlib/codecs.pyi @@ -223,7 +223,7 @@ class Codec: # These are sort of @abstractmethod but sort of not. # The StreamReader and StreamWriter subclasses only implement one. def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder: errors: str diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index 461965f3868d..c286514af229 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import Any, Generic, ParamSpec, Protocol, TypeAlias, TypeVar, overload, runtime_checkable, type_check_only -from typing_extensions import Self +from typing_extensions import Self, deprecated __all__ = [ "aclosing", @@ -84,6 +84,12 @@ class _GeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... +@overload +def contextmanager(func: Callable[_P, Generator[_T_co, None, object]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... +@overload +@deprecated( + "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead." +) def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]]) @@ -101,6 +107,13 @@ class _AsyncGeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... +@overload +def asynccontextmanager(func: Callable[_P, AsyncGenerator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... +@overload +@deprecated( + "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. " + "Use `-> AsyncGenerator[Foo]` instead." +) def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... @type_check_only diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index 18b36b20160f..751e85566f88 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -21,7 +21,7 @@ if sys.version_info >= (3, 12): from _csv import QUOTE_NOTNULL as QUOTE_NOTNULL, QUOTE_STRINGS as QUOTE_STRINGS from _csv import Reader, Writer from _typeshed import SupportsWrite -from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence +from collections.abc import Collection, Iterable, Mapping, Sequence from types import GenericAlias from typing import Any, Generic, Literal, TypeVar, overload from typing_extensions import Self @@ -73,7 +73,7 @@ class excel(Dialect): ... class excel_tab(excel): ... class unix_dialect(Dialect): ... -class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]): +class DictReader(Generic[_T]): fieldnames: Sequence[_T] | None restkey: _T | None restval: str | Any | None diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi index 0a21f72b09de..5272e3850fe7 100644 --- a/mypy/typeshed/stdlib/datetime.pyi +++ b/mypy/typeshed/stdlib/datetime.pyi @@ -1,7 +1,7 @@ import sys from abc import abstractmethod from time import struct_time -from typing import ClassVar, Final, SupportsIndex, TypeAlias, final, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base if sys.version_info >= (3, 11): @@ -266,10 +266,14 @@ class timedelta: def __bool__(self) -> bool: ... def __hash__(self) -> int: ... +_TzInfoT = TypeVar("_TzInfoT", bound=tzinfo | None, default=Any) + @disjoint_base -class datetime(date): - min: ClassVar[datetime] - max: ClassVar[datetime] +class datetime(date, Generic[_TzInfoT]): + min: ClassVar[datetime[None]] + max: ClassVar[datetime[None]] + + @overload def __new__( cls, year: SupportsIndex, @@ -279,10 +283,39 @@ class datetime(date): minute: SupportsIndex = 0, second: SupportsIndex = 0, microsecond: SupportsIndex = 0, - tzinfo: _TzInfo | None = None, + tzinfo: None = None, *, fold: int = 0, - ) -> Self: ... + ) -> datetime[None]: ... + @overload + def __new__( + cls, + year: SupportsIndex, + month: SupportsIndex, + day: SupportsIndex, + hour: SupportsIndex = 0, + minute: SupportsIndex = 0, + second: SupportsIndex = 0, + microsecond: SupportsIndex = 0, + *, + tzinfo: _TzInfo, + fold: int = 0, + ) -> datetime[_TzInfo]: ... + @overload + def __new__( + cls, + year: SupportsIndex, + month: SupportsIndex, + day: SupportsIndex, + hour: SupportsIndex, + minute: SupportsIndex, + second: SupportsIndex, + microsecond: SupportsIndex, + tzinfo: _TzInfo, + *, + fold: int = 0, + ) -> datetime[_TzInfo]: ... + @property def hour(self) -> int: ... @property @@ -292,32 +325,64 @@ class datetime(date): @property def microsecond(self) -> int: ... @property - def tzinfo(self) -> _TzInfo | None: ... + def tzinfo(self) -> _TzInfoT: ... @property def fold(self) -> int: ... # On <3.12, the name of the first parameter in the pure-Python implementation # didn't match the name in the C implementation, # meaning it is only *safe* to pass it as a keyword argument on 3.12+ if sys.version_info >= (3, 12): + @overload # type: ignore[override] + @classmethod + def fromtimestamp(cls, timestamp: float, tz: None = None) -> datetime[None]: ... + @overload @classmethod - def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = None) -> Self: ... + def fromtimestamp(cls, timestamp: float, tz: _TzInfo) -> datetime[_TzInfo]: ... + @overload + @classmethod + def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... + else: + @overload # type: ignore[override] + @classmethod + def fromtimestamp(cls, timestamp: float, /, tz: None = None) -> datetime[None]: ... + @overload + @classmethod + def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo) -> datetime[_TzInfo]: ... + @overload + @classmethod + def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... + + # fromisoformat returns Self, but we can't specialize "Self" + if sys.version_info >= (3, 15): + @classmethod + def fromisoformat(cls, string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] else: @classmethod - def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None = None) -> Self: ... + def fromisoformat(cls, date_string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] @classmethod - @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.timezone.utc)") - def utcfromtimestamp(cls, t: float, /) -> Self: ... + @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.UTC)") + def utcfromtimestamp(cls, t: float, /) -> datetime[None]: ... + + @overload @classmethod - def now(cls, tz: _TzInfo | None = None) -> Self: ... + def now(cls, tz: None = None) -> datetime[None]: ... + @overload @classmethod - @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.timezone.utc)") - def utcnow(cls) -> Self: ... + def now(cls, tz: _TzInfo) -> datetime[_TzInfo]: ... + @classmethod - def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ... - if sys.version_info >= (3, 15): - @classmethod - def fromisoformat(cls, string: str, /) -> Self: ... + def today(cls) -> datetime[None]: ... # type: ignore[override] + @classmethod + @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") + def utcnow(cls) -> datetime[None]: ... + + @overload + @classmethod + def combine(cls, date: _Date, time: _Time, tzinfo: None = None) -> datetime[None]: ... + @overload + @classmethod + def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo) -> datetime[_TzInfo]: ... def timestamp(self) -> float: ... def utctimetuple(self) -> struct_time: ... @@ -340,6 +405,7 @@ class datetime(date): fold: int = ..., ) -> Self: ... + @overload def replace( self, year: SupportsIndex = ..., @@ -349,11 +415,67 @@ class datetime(date): minute: SupportsIndex = ..., second: SupportsIndex = ..., microsecond: SupportsIndex = ..., - tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... - def astimezone(self, tz: _TzInfo | None = None) -> Self: ... + @overload + def replace( + self, + year: SupportsIndex, + month: SupportsIndex, + day: SupportsIndex, + hour: SupportsIndex, + minute: SupportsIndex, + second: SupportsIndex, + microsecond: SupportsIndex, + tzinfo: _TzInfo, + *, + fold: int = ..., + ) -> datetime[_TzInfo]: ... + @overload + def replace( + self, + year: SupportsIndex = ..., + month: SupportsIndex = ..., + day: SupportsIndex = ..., + hour: SupportsIndex = ..., + minute: SupportsIndex = ..., + second: SupportsIndex = ..., + microsecond: SupportsIndex = ..., + *, + tzinfo: _TzInfo, + fold: int = ..., + ) -> datetime[_TzInfo]: ... + @overload + def replace( + self, + year: SupportsIndex, + month: SupportsIndex, + day: SupportsIndex, + hour: SupportsIndex, + minute: SupportsIndex, + second: SupportsIndex, + microsecond: SupportsIndex, + tzinfo: None, + *, + fold: int = ..., + ) -> datetime[None]: ... + @overload + def replace( + self, + year: SupportsIndex = ..., + month: SupportsIndex = ..., + day: SupportsIndex = ..., + hour: SupportsIndex = ..., + minute: SupportsIndex = ..., + second: SupportsIndex = ..., + microsecond: SupportsIndex = ..., + *, + tzinfo: None, + fold: int = ..., + ) -> datetime[None]: ... + + def astimezone(self, tz: _TzInfo | None = None) -> datetime[_TzInfo]: ... def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: ... if sys.version_info >= (3, 15): @@ -366,15 +488,56 @@ class datetime(date): def utcoffset(self) -> timedelta | None: ... def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... - def __le__(self, value: datetime, /) -> bool: ... # type: ignore[override] - def __lt__(self, value: datetime, /) -> bool: ... # type: ignore[override] - def __ge__(self, value: datetime, /) -> bool: ... # type: ignore[override] - def __gt__(self, value: datetime, /) -> bool: ... # type: ignore[override] + + @overload # type: ignore[override] + def __le__( # type: ignore[overload-overlap] + self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / + ) -> bool: ... # type: ignore[misc] + @overload + def __le__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] + @overload + def __le__(self: datetime[Any], value: datetime[Any], /) -> Never: ... + + @overload # type: ignore[override] + def __lt__( # type: ignore[overload-overlap] + self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / + ) -> bool: ... # type: ignore[misc] + @overload + def __lt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] + @overload + def __lt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... + + @overload # type: ignore[override] + def __ge__( # type: ignore[overload-overlap] + self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / + ) -> bool: ... # type: ignore[misc] + @overload + def __ge__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] + @overload + def __ge__(self: datetime[Any], value: datetime[Any], /) -> Never: ... + + @overload # type: ignore[override] + def __gt__( # type: ignore[overload-overlap] + self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / + ) -> bool: ... # type: ignore[misc] + @overload + def __gt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] + @overload + def __gt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... + def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... @overload # type: ignore[override] - def __sub__(self, value: Self, /) -> timedelta: ... + def __sub__( # type: ignore[overload-overlap] + self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / + ) -> timedelta: ... + @overload + def __sub__( # type: ignore[overload-overlap] + self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], / + ) -> timedelta: ... + @overload + def __sub__(self: datetime[Any], value: datetime[Any], /) -> Never: ... @overload def __sub__(self, value: timedelta, /) -> Self: ... diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index 0ad928934671..984f932e3311 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -2,7 +2,7 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, Final, NamedTuple, overload +from typing import IO, Any, Final, NamedTuple, TypeAlias, overload from typing_extensions import Self, deprecated, disjoint_base __all__ = [ @@ -41,7 +41,7 @@ else: # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] if sys.version_info >= (3, 11): class Positions(NamedTuple): diff --git a/mypy/typeshed/stdlib/email/_header_value_parser.pyi b/mypy/typeshed/stdlib/email/_header_value_parser.pyi index 019503cf8538..de974b9c37dd 100644 --- a/mypy/typeshed/stdlib/email/_header_value_parser.pyi +++ b/mypy/typeshed/stdlib/email/_header_value_parser.pyi @@ -47,6 +47,10 @@ class TokenList(list[TokenList | Terminal]): def as_ew_allowed(self) -> bool: ... @property def comments(self) -> list[str]: ... + if sys.version_info >= (3, 11): + # Added in Python 3.11.18, 3.12.16, 3.13.18, 3.14.9 and 3.15.1. + def contains_token_type(self, *token_types: str | None) -> bool: ... + def fold(self, *, policy: Policy) -> str: ... def pprint(self, indent: str = "") -> None: ... def ppstr(self, indent: str = "") -> str: ... @@ -339,6 +343,10 @@ class Terminal(str): def pop_trailing_ws(self) -> None: ... @property def comments(self) -> list[str]: ... + if sys.version_info >= (3, 11): + # Added in Python 3.11.18, 3.12.16, 3.13.18, 3.14.9 and 3.15.1. + def contains_token_type(self, *token_types: str | None) -> bool: ... + def __getnewargs__(self) -> tuple[str, str]: ... # type: ignore[override] class WhiteSpaceTerminal(Terminal): diff --git a/mypy/typeshed/stdlib/email/base64mime.pyi b/mypy/typeshed/stdlib/email/base64mime.pyi index 563cd7f669a2..f19cd92c2f12 100644 --- a/mypy/typeshed/stdlib/email/base64mime.pyi +++ b/mypy/typeshed/stdlib/email/base64mime.pyi @@ -2,11 +2,11 @@ __all__ = ["body_decode", "body_encode", "decode", "decodestring", "header_encod from _typeshed import ReadableBuffer -def header_length(bytearray: str | bytes | bytearray) -> int: ... +def header_length(bytearray: str | bytes | bytearray | memoryview) -> int: ... def header_encode(header_bytes: str | ReadableBuffer, charset: str = "iso-8859-1") -> str: ... # First argument should be a buffer that supports slicing and len(). -def body_encode(s: bytes | bytearray, maxlinelen: int = 76, eol: str = "\n") -> str: ... +def body_encode(s: bytes | bytearray | memoryview, maxlinelen: int = 76, eol: str = "\n") -> str: ... def decode(string: str | ReadableBuffer) -> bytes: ... body_decode = decode diff --git a/mypy/typeshed/stdlib/encodings/cp037.pyi b/mypy/typeshed/stdlib/encodings/cp037.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp037.pyi +++ b/mypy/typeshed/stdlib/encodings/cp037.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1006.pyi b/mypy/typeshed/stdlib/encodings/cp1006.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1006.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1006.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1026.pyi b/mypy/typeshed/stdlib/encodings/cp1026.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1026.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1026.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1125.pyi b/mypy/typeshed/stdlib/encodings/cp1125.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp1125.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1125.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1140.pyi b/mypy/typeshed/stdlib/encodings/cp1140.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1140.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1140.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1250.pyi b/mypy/typeshed/stdlib/encodings/cp1250.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1250.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1250.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1251.pyi b/mypy/typeshed/stdlib/encodings/cp1251.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1251.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1251.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1252.pyi b/mypy/typeshed/stdlib/encodings/cp1252.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1252.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1252.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1253.pyi b/mypy/typeshed/stdlib/encodings/cp1253.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1253.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1253.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1254.pyi b/mypy/typeshed/stdlib/encodings/cp1254.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1254.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1254.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1255.pyi b/mypy/typeshed/stdlib/encodings/cp1255.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1255.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1255.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1256.pyi b/mypy/typeshed/stdlib/encodings/cp1256.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1256.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1256.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1257.pyi b/mypy/typeshed/stdlib/encodings/cp1257.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1257.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1257.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp1258.pyi b/mypy/typeshed/stdlib/encodings/cp1258.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp1258.pyi +++ b/mypy/typeshed/stdlib/encodings/cp1258.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp273.pyi b/mypy/typeshed/stdlib/encodings/cp273.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp273.pyi +++ b/mypy/typeshed/stdlib/encodings/cp273.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp424.pyi b/mypy/typeshed/stdlib/encodings/cp424.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp424.pyi +++ b/mypy/typeshed/stdlib/encodings/cp424.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp437.pyi b/mypy/typeshed/stdlib/encodings/cp437.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp437.pyi +++ b/mypy/typeshed/stdlib/encodings/cp437.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp500.pyi b/mypy/typeshed/stdlib/encodings/cp500.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp500.pyi +++ b/mypy/typeshed/stdlib/encodings/cp500.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp720.pyi b/mypy/typeshed/stdlib/encodings/cp720.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp720.pyi +++ b/mypy/typeshed/stdlib/encodings/cp720.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp737.pyi b/mypy/typeshed/stdlib/encodings/cp737.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp737.pyi +++ b/mypy/typeshed/stdlib/encodings/cp737.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp775.pyi b/mypy/typeshed/stdlib/encodings/cp775.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp775.pyi +++ b/mypy/typeshed/stdlib/encodings/cp775.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp850.pyi b/mypy/typeshed/stdlib/encodings/cp850.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp850.pyi +++ b/mypy/typeshed/stdlib/encodings/cp850.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp852.pyi b/mypy/typeshed/stdlib/encodings/cp852.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp852.pyi +++ b/mypy/typeshed/stdlib/encodings/cp852.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp855.pyi b/mypy/typeshed/stdlib/encodings/cp855.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp855.pyi +++ b/mypy/typeshed/stdlib/encodings/cp855.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp856.pyi b/mypy/typeshed/stdlib/encodings/cp856.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp856.pyi +++ b/mypy/typeshed/stdlib/encodings/cp856.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp857.pyi b/mypy/typeshed/stdlib/encodings/cp857.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp857.pyi +++ b/mypy/typeshed/stdlib/encodings/cp857.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp858.pyi b/mypy/typeshed/stdlib/encodings/cp858.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp858.pyi +++ b/mypy/typeshed/stdlib/encodings/cp858.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp860.pyi b/mypy/typeshed/stdlib/encodings/cp860.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp860.pyi +++ b/mypy/typeshed/stdlib/encodings/cp860.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp861.pyi b/mypy/typeshed/stdlib/encodings/cp861.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp861.pyi +++ b/mypy/typeshed/stdlib/encodings/cp861.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp862.pyi b/mypy/typeshed/stdlib/encodings/cp862.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp862.pyi +++ b/mypy/typeshed/stdlib/encodings/cp862.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp863.pyi b/mypy/typeshed/stdlib/encodings/cp863.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp863.pyi +++ b/mypy/typeshed/stdlib/encodings/cp863.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp864.pyi b/mypy/typeshed/stdlib/encodings/cp864.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp864.pyi +++ b/mypy/typeshed/stdlib/encodings/cp864.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp865.pyi b/mypy/typeshed/stdlib/encodings/cp865.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp865.pyi +++ b/mypy/typeshed/stdlib/encodings/cp865.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp866.pyi b/mypy/typeshed/stdlib/encodings/cp866.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp866.pyi +++ b/mypy/typeshed/stdlib/encodings/cp866.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp869.pyi b/mypy/typeshed/stdlib/encodings/cp869.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/cp869.pyi +++ b/mypy/typeshed/stdlib/encodings/cp869.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp874.pyi b/mypy/typeshed/stdlib/encodings/cp874.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp874.pyi +++ b/mypy/typeshed/stdlib/encodings/cp874.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/cp875.pyi b/mypy/typeshed/stdlib/encodings/cp875.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/cp875.pyi +++ b/mypy/typeshed/stdlib/encodings/cp875.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/hp_roman8.pyi b/mypy/typeshed/stdlib/encodings/hp_roman8.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/hp_roman8.pyi +++ b/mypy/typeshed/stdlib/encodings/hp_roman8.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_1.pyi b/mypy/typeshed/stdlib/encodings/iso8859_1.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_1.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_1.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_10.pyi b/mypy/typeshed/stdlib/encodings/iso8859_10.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_10.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_10.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_11.pyi b/mypy/typeshed/stdlib/encodings/iso8859_11.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_11.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_11.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_13.pyi b/mypy/typeshed/stdlib/encodings/iso8859_13.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_13.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_13.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_14.pyi b/mypy/typeshed/stdlib/encodings/iso8859_14.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_14.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_14.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_15.pyi b/mypy/typeshed/stdlib/encodings/iso8859_15.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_15.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_15.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_16.pyi b/mypy/typeshed/stdlib/encodings/iso8859_16.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_16.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_16.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_2.pyi b/mypy/typeshed/stdlib/encodings/iso8859_2.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_2.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_2.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_3.pyi b/mypy/typeshed/stdlib/encodings/iso8859_3.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_3.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_3.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_4.pyi b/mypy/typeshed/stdlib/encodings/iso8859_4.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_4.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_4.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_5.pyi b/mypy/typeshed/stdlib/encodings/iso8859_5.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_5.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_5.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_6.pyi b/mypy/typeshed/stdlib/encodings/iso8859_6.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_6.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_6.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_7.pyi b/mypy/typeshed/stdlib/encodings/iso8859_7.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_7.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_7.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_8.pyi b/mypy/typeshed/stdlib/encodings/iso8859_8.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_8.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_8.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/iso8859_9.pyi b/mypy/typeshed/stdlib/encodings/iso8859_9.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/iso8859_9.pyi +++ b/mypy/typeshed/stdlib/encodings/iso8859_9.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/koi8_r.pyi b/mypy/typeshed/stdlib/encodings/koi8_r.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/koi8_r.pyi +++ b/mypy/typeshed/stdlib/encodings/koi8_r.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/koi8_t.pyi b/mypy/typeshed/stdlib/encodings/koi8_t.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/koi8_t.pyi +++ b/mypy/typeshed/stdlib/encodings/koi8_t.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/koi8_u.pyi b/mypy/typeshed/stdlib/encodings/koi8_u.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/koi8_u.pyi +++ b/mypy/typeshed/stdlib/encodings/koi8_u.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/kz1048.pyi b/mypy/typeshed/stdlib/encodings/kz1048.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/kz1048.pyi +++ b/mypy/typeshed/stdlib/encodings/kz1048.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_arabic.pyi b/mypy/typeshed/stdlib/encodings/mac_arabic.pyi index 42781b489298..d2aa4e779744 100644 --- a/mypy/typeshed/stdlib/encodings/mac_arabic.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_arabic.pyi @@ -3,7 +3,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_croatian.pyi b/mypy/typeshed/stdlib/encodings/mac_croatian.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_croatian.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_croatian.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_cyrillic.pyi b/mypy/typeshed/stdlib/encodings/mac_cyrillic.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_cyrillic.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_cyrillic.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_farsi.pyi b/mypy/typeshed/stdlib/encodings/mac_farsi.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_farsi.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_farsi.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_greek.pyi b/mypy/typeshed/stdlib/encodings/mac_greek.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_greek.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_greek.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_iceland.pyi b/mypy/typeshed/stdlib/encodings/mac_iceland.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_iceland.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_iceland.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_latin2.pyi b/mypy/typeshed/stdlib/encodings/mac_latin2.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_latin2.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_latin2.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_roman.pyi b/mypy/typeshed/stdlib/encodings/mac_roman.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_roman.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_roman.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_romanian.pyi b/mypy/typeshed/stdlib/encodings/mac_romanian.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_romanian.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_romanian.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/mac_turkish.pyi b/mypy/typeshed/stdlib/encodings/mac_turkish.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/mac_turkish.pyi +++ b/mypy/typeshed/stdlib/encodings/mac_turkish.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/palmos.pyi b/mypy/typeshed/stdlib/encodings/palmos.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/palmos.pyi +++ b/mypy/typeshed/stdlib/encodings/palmos.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/ptcp154.pyi b/mypy/typeshed/stdlib/encodings/ptcp154.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/ptcp154.pyi +++ b/mypy/typeshed/stdlib/encodings/ptcp154.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/encodings/punycode.pyi b/mypy/typeshed/stdlib/encodings/punycode.pyi index eb99e667b416..7612464f7d56 100644 --- a/mypy/typeshed/stdlib/encodings/punycode.pyi +++ b/mypy/typeshed/stdlib/encodings/punycode.pyi @@ -1,4 +1,5 @@ import codecs +from _typeshed import ReadableBuffer from typing import Literal def segregate(str: str) -> tuple[bytes, list[int]]: ... @@ -19,13 +20,13 @@ def punycode_decode(text: memoryview | bytes | bytearray | str, errors: str) -> class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: memoryview | bytes | bytearray | str, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: str | ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... class IncrementalDecoder(codecs.IncrementalDecoder): - def decode(self, input: memoryview | bytes | bytearray | str, final: bool = False) -> str: ... # type: ignore[override] + def decode(self, input: str | ReadableBuffer, final: bool = False) -> str: ... class StreamWriter(Codec, codecs.StreamWriter): ... class StreamReader(Codec, codecs.StreamReader): ... diff --git a/mypy/typeshed/stdlib/encodings/tis_620.pyi b/mypy/typeshed/stdlib/encodings/tis_620.pyi index f62195662ce9..2924e73c3543 100644 --- a/mypy/typeshed/stdlib/encodings/tis_620.pyi +++ b/mypy/typeshed/stdlib/encodings/tis_620.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer class Codec(codecs.Codec): def encode(self, input: str, errors: str = "strict") -> tuple[bytes, int]: ... - def decode(self, input: bytes, errors: str = "strict") -> tuple[str, int]: ... + def decode(self, input: ReadableBuffer, errors: str = "strict") -> tuple[str, int]: ... class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input: str, final: bool = False) -> bytes: ... diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index db9c228f5f28..37783254c70f 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,8 +1,8 @@ import sys from _typeshed import AnyStr_co, StrOrBytesPath -from collections.abc import Callable, Iterable, Iterator +from collections.abc import Callable, Iterable from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Literal, Protocol, TypeAlias, overload, type_check_only +from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import Self, deprecated __all__ = [ @@ -74,7 +74,7 @@ def fileno() -> int: ... def isfirstline() -> bool: ... def isstdin() -> bool: ... -class FileInput(Iterator[AnyStr]): +class FileInput(Generic[AnyStr]): # encoding and errors are added @overload def __init__( diff --git a/mypy/typeshed/stdlib/functools.pyi b/mypy/typeshed/stdlib/functools.pyi index 23260ab90855..42041befd999 100644 --- a/mypy/typeshed/stdlib/functools.pyi +++ b/mypy/typeshed/stdlib/functools.pyi @@ -46,6 +46,7 @@ _PWrapper = ParamSpec("_PWrapper") _RWrapper = TypeVar("_RWrapper") _WrapperSelfT = TypeVar("_WrapperSelfT") _PBound = ParamSpec("_PBound") +_CacheArgT_contra = TypeVar("_CacheArgT_contra", contravariant=True, default=Hashable) if sys.version_info >= (3, 14): @overload @@ -65,23 +66,27 @@ class _CacheInfo(NamedTuple): @type_check_only class _CacheParameters(TypedDict): - maxsize: int + maxsize: int | None typed: bool @final -class _lru_cache_wrapper(Generic[_T_co]): +class _lru_cache_wrapper(Generic[_T_co, _CacheArgT_contra]): __wrapped__: Callable[..., _T_co] - def __call__(self, *args: Hashable, **kwargs: Hashable) -> _T_co: ... + def __call__(self, /, *args: _CacheArgT_contra, **kwargs: _CacheArgT_contra) -> _T_co: ... def cache_info(self) -> _CacheInfo: ... def cache_clear(self) -> None: ... def cache_parameters(self) -> _CacheParameters: ... - def __copy__(self) -> _lru_cache_wrapper[_T_co]: ... - def __deepcopy__(self, memo: Any, /) -> _lru_cache_wrapper[_T_co]: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, memo: Any, /) -> Self: ... # as with ``Callable``, we'll assume that these attributes exist __name__: str __qualname__: str +@overload +def lru_cache( + maxsize: Literal[0, False], typed: bool = False +) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T, object]]: ... @overload def lru_cache(maxsize: int | None = 128, typed: bool = False) -> Callable[[Callable[..., _T]], _lru_cache_wrapper[_T]]: ... @overload diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 410264820ece..9bca21ab2dfd 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -195,8 +195,8 @@ if sys.version_info >= (3, 14): modulesbyfile: dict[str, Any] -_GetMembersPredicateTypeGuard = Callable[[Any], TypeGuard[_T]] -_GetMembersPredicateTypeIs = Callable[[Any], TypeIs[_T]] +_GetMembersPredicateTypeGuard: TypeAlias = Callable[[Any], TypeGuard[_T]] +_GetMembersPredicateTypeIs: TypeAlias = Callable[[Any], TypeIs[_T]] _GetMembersPredicate: TypeAlias = Callable[[Any], bool] _GetMembersReturn: TypeAlias = list[tuple[str, _T]] diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index fd7daf11e808..d26a4e1da21e 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -23,12 +23,12 @@ _T10 = TypeVar("_T10") _Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex -_Predicate = Callable[[_T], object] +_Predicate: TypeAlias = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method @disjoint_base -class count(Iterator[_N]): +class count(Generic[_N]): @overload def __new__(cls) -> count[int]: ... @overload @@ -40,13 +40,13 @@ class count(Iterator[_N]): def __iter__(self) -> Self: ... @disjoint_base -class cycle(Iterator[_T]): +class cycle(Generic[_T]): def __new__(cls, iterable: Iterable[_T], /) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @disjoint_base -class repeat(Iterator[_T]): +class repeat(Generic[_T]): @overload def __new__(cls, object: _T) -> Self: ... @overload @@ -57,7 +57,7 @@ class repeat(Iterator[_T]): def __length_hint__(self) -> int: ... @disjoint_base -class accumulate(Iterator[_T]): +class accumulate(Generic[_T]): @overload def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload @@ -67,7 +67,7 @@ class accumulate(Iterator[_T]): def __next__(self) -> _T: ... @disjoint_base -class chain(Iterator[_T]): +class chain(Generic[_T]): def __new__(cls, *iterables: Iterable[_T]) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @@ -77,25 +77,25 @@ class chain(Iterator[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class compress(Iterator[_T]): +class compress(Generic[_T]): def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class dropwhile(Iterator[_T]): +class dropwhile(Generic[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class filterfalse(Iterator[_T]): +class filterfalse(Generic[_T]): def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): +class groupby(Generic[_T_co, _S_co]): @overload def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload @@ -105,7 +105,7 @@ class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ... @disjoint_base -class islice(Iterator[_T]): +class islice(Generic[_T]): @overload def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... @overload @@ -115,13 +115,13 @@ class islice(Iterator[_T]): def __next__(self) -> _T: ... @disjoint_base -class starmap(Iterator[_T_co]): +class starmap(Generic[_T_co]): def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... @disjoint_base -class takewhile(Iterator[_T]): +class takewhile(Generic[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -129,7 +129,7 @@ class takewhile(Iterator[_T]): def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... @disjoint_base -class zip_longest(Iterator[_T_co]): +class zip_longest(Generic[_T_co]): # one iterable (fillvalue doesn't matter) @overload def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... @@ -209,7 +209,7 @@ class zip_longest(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class product(Iterator[_T_co]): +class product(Generic[_T_co]): @overload def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ... @overload @@ -296,7 +296,7 @@ class product(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class permutations(Iterator[_T_co]): +class permutations(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ... @overload @@ -312,7 +312,7 @@ class permutations(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations(Iterator[_T_co]): +class combinations(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ... @overload @@ -328,7 +328,7 @@ class combinations(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations_with_replacement(Iterator[_T_co]): +class combinations_with_replacement(Generic[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ... @overload @@ -344,14 +344,14 @@ class combinations_with_replacement(Iterator[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class pairwise(Iterator[_T_co]): +class pairwise(Generic[_T_co]): def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): @disjoint_base - class batched(Iterator[_T_co], Generic[_T_co]): + class batched(Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/context.pyi b/mypy/typeshed/stdlib/multiprocessing/context.pyi index 13fd967515d0..925f364f1826 100644 --- a/mypy/typeshed/stdlib/multiprocessing/context.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/context.pyi @@ -169,7 +169,12 @@ class Process(BaseProcess): class DefaultContext(BaseContext): Process: ClassVar[type[Process]] - def __init__(self, context: BaseContext) -> None: ... + if sys.version_info >= (3, 14): + # The context parameter became optional in Python 3.14.9 and 3.15.1. + def __init__(self, context: BaseContext | None = None) -> None: ... + else: + def __init__(self, context: BaseContext) -> None: ... + def get_start_method(self, allow_none: bool = False) -> str: ... def get_all_start_methods(self) -> list[str]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/managers.pyi b/mypy/typeshed/stdlib/multiprocessing/managers.pyi index 0f1d4e87b0dc..0727f60f1080 100644 --- a/mypy/typeshed/stdlib/multiprocessing/managers.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/managers.pyi @@ -195,7 +195,7 @@ if sys.version_info >= (3, 14): def __rand__(self, value: AbstractSet[object], /) -> set[_T]: ... def __ror__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[misc] def __rsub__(self, value: AbstractSet[_T], /) -> set[_T]: ... - def __rxor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[misc] + def __rxor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[override,misc] def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... class SetProxy(_BaseSetProxy[_T]): ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index 203c5887ca7e..5642e50d0e76 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable, Iterable, Iterator, Mapping +from collections.abc import Callable, Iterable, Mapping from multiprocessing.context import DefaultContext, Process as _Process from types import GenericAlias, TracebackType from typing import Any, Final, Generic, TypeVar @@ -32,7 +32,7 @@ class MapResult(ApplyResult[list[_T]]): error_callback: Callable[[BaseException], object] | None, ) -> None: ... -class IMapIterator(Iterator[_T]): +class IMapIterator(Generic[_T]): def __init__(self, pool: Pool) -> None: ... def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... diff --git a/mypy/typeshed/stdlib/os/__init__.pyi b/mypy/typeshed/stdlib/os/__init__.pyi index 89b9bd866420..008a8d607211 100644 --- a/mypy/typeshed/stdlib/os/__init__.pyi +++ b/mypy/typeshed/stdlib/os/__init__.pyi @@ -234,12 +234,15 @@ if sys.platform == "linux" and sys.version_info >= (3, 15): "AT_STATX_DONT_SYNC", "AT_STATX_FORCE_SYNC", "AT_STATX_SYNC_AS_STAT", + "RWF_ATOMIC", + "RWF_DONTCACHE", "STATX_ATIME", "STATX_BASIC_STATS", "STATX_BLOCKS", "STATX_BTIME", "STATX_CTIME", "STATX_DIOALIGN", + "STATX_DIO_READ_ALIGN", "STATX_GID", "STATX_INO", "STATX_MNT_ID", @@ -248,8 +251,10 @@ if sys.platform == "linux" and sys.version_info >= (3, 15): "STATX_MTIME", "STATX_NLINK", "STATX_SIZE", + "STATX_SUBVOL", "STATX_TYPE", "STATX_UID", + "STATX_WRITE_ATOMIC", "statx", "statx_result", ] @@ -703,12 +708,15 @@ if sys.platform == "linux" and sys.version_info >= (3, 15): AT_STATX_DONT_SYNC: Final[int] AT_STATX_FORCE_SYNC: Final[int] AT_STATX_SYNC_AS_STAT: Final[int] + RWF_ATOMIC: Final[int] + RWF_DONTCACHE: Final[int] STATX_ATIME: Final[int] STATX_BASIC_STATS: Final[int] STATX_BLOCKS: Final[int] STATX_BTIME: Final[int] STATX_CTIME: Final[int] STATX_DIOALIGN: Final[int] + STATX_DIO_READ_ALIGN: Final[int] STATX_GID: Final[int] STATX_INO: Final[int] STATX_MNT_ID: Final[int] @@ -717,8 +725,10 @@ if sys.platform == "linux" and sys.version_info >= (3, 15): STATX_MTIME: Final[int] STATX_NLINK: Final[int] STATX_SIZE: Final[int] + STATX_SUBVOL: Final[int] STATX_TYPE: Final[int] STATX_UID: Final[int] + STATX_WRITE_ATOMIC: Final[int] if sys.platform != "win32": O_FSYNC: Final[int] @@ -1408,6 +1418,18 @@ if sys.platform == "linux" and sys.version_info >= (3, 15): def stx_dio_mem_align(self) -> int | None: ... @property def stx_dio_offset_align(self) -> int | None: ... + @property + def stx_subvol(self) -> int | None: ... + @property + def stx_atomic_write_unit_min(self) -> int | None: ... + @property + def stx_atomic_write_unit_max(self) -> int | None: ... + @property + def stx_atomic_write_segments_max(self) -> int | None: ... + @property + def stx_dio_read_offset_align(self) -> int | None: ... + @property + def stx_atomic_write_unit_max_opt(self) -> int | None: ... def statx( path: FileDescriptorOrPath, mask: int, *, flags: int = 0, dir_fd: int | None = None, follow_symlinks: bool = True diff --git a/mypy/typeshed/stdlib/posix.pyi b/mypy/typeshed/stdlib/posix.pyi index 36bb5be18e88..c8bbc098b0b0 100644 --- a/mypy/typeshed/stdlib/posix.pyi +++ b/mypy/typeshed/stdlib/posix.pyi @@ -272,11 +272,14 @@ if sys.platform != "win32": AT_STATX_DONT_SYNC as AT_STATX_DONT_SYNC, AT_STATX_FORCE_SYNC as AT_STATX_FORCE_SYNC, AT_STATX_SYNC_AS_STAT as AT_STATX_SYNC_AS_STAT, + RWF_ATOMIC as RWF_ATOMIC, + RWF_DONTCACHE as RWF_DONTCACHE, STATX_ATIME as STATX_ATIME, STATX_BASIC_STATS as STATX_BASIC_STATS, STATX_BLOCKS as STATX_BLOCKS, STATX_BTIME as STATX_BTIME, STATX_CTIME as STATX_CTIME, + STATX_DIO_READ_ALIGN as STATX_DIO_READ_ALIGN, STATX_DIOALIGN as STATX_DIOALIGN, STATX_GID as STATX_GID, STATX_INO as STATX_INO, @@ -286,8 +289,10 @@ if sys.platform != "win32": STATX_MTIME as STATX_MTIME, STATX_NLINK as STATX_NLINK, STATX_SIZE as STATX_SIZE, + STATX_SUBVOL as STATX_SUBVOL, STATX_TYPE as STATX_TYPE, STATX_UID as STATX_UID, + STATX_WRITE_ATOMIC as STATX_WRITE_ATOMIC, _clearenv as _clearenv, statx as statx, statx_result as statx_result, diff --git a/mypy/typeshed/stdlib/re.pyi b/mypy/typeshed/stdlib/re.pyi index f0a892c797e9..42eb751498c0 100644 --- a/mypy/typeshed/stdlib/re.pyi +++ b/mypy/typeshed/stdlib/re.pyi @@ -339,7 +339,11 @@ def subn( flags: _FlagsType = 0, ) -> tuple[bytes, int]: ... +@overload def escape(pattern: AnyStr) -> AnyStr: ... +@overload +def escape(pattern: ReadableBuffer) -> bytes: ... + def purge() -> None: ... if sys.version_info < (3, 13): diff --git a/mypy/typeshed/stdlib/socket.pyi b/mypy/typeshed/stdlib/socket.pyi index 4731aeab82c1..948092d3ce18 100644 --- a/mypy/typeshed/stdlib/socket.pyi +++ b/mypy/typeshed/stdlib/socket.pyi @@ -136,7 +136,7 @@ from _socket import ( from _typeshed import ReadableBuffer, Unused, WriteableBuffer from collections.abc import Iterable from enum import IntEnum, IntFlag -from io import BufferedReader, BufferedRWPair, BufferedWriter, IOBase, RawIOBase, TextIOWrapper +from io import BufferedReader, BufferedRWPair, BufferedWriter, RawIOBase, TextIOWrapper from typing import Any, Final, Literal, Protocol, SupportsIndex, TypeAlias, overload, type_check_only from typing_extensions import Self @@ -961,6 +961,11 @@ if sys.platform == "linux" and sys.version_info >= (3, 13): __all__ += ["NI_IDN", "SO_BINDTOIFINDEX"] +if sys.platform == "linux" and sys.version_info >= (3, 15): + from _socket import SO_PASSRIGHTS as SO_PASSRIGHTS + + __all__ += ["SO_PASSRIGHTS"] + if sys.version_info >= (3, 12): from _socket import ( IP_ADD_SOURCE_MEMBERSHIP as IP_ADD_SOURCE_MEMBERSHIP, @@ -1507,7 +1512,7 @@ class socket(_socket.socket): encoding: str | None = None, errors: str | None = None, newline: str | None = None, - ) -> IOBase: ... + ) -> SocketIO | BufferedRWPair | BufferedReader | BufferedWriter: ... @overload def makefile( self, diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi index d1065a509af5..80a02079dd05 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi @@ -437,7 +437,7 @@ class Connection: ) -> Literal[False]: ... @disjoint_base -class Cursor(Iterator[Any]): +class Cursor: arraysize: int @property def connection(self) -> Connection: ... diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index 9b5344b326ce..ac53089b8d82 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -1,15 +1,15 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, Union, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, final, type_check_only _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] if sys.version_info >= (3, 15): # anticipate on https://github.com/python/cpython/pull/139224 - _SupportsFloatOrIndex: TypeAlias = Union[SupportsFloat, SupportsIndex] + _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex else: # before, time functions only accept (subclass of) float, *not* SupportsFloat - _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex] + _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex altzone: int daylight: int diff --git a/mypy/typeshed/stdlib/tkinter/filedialog.pyi b/mypy/typeshed/stdlib/tkinter/filedialog.pyi index b6ef8f45d035..b1e4b27edb83 100644 --- a/mypy/typeshed/stdlib/tkinter/filedialog.pyi +++ b/mypy/typeshed/stdlib/tkinter/filedialog.pyi @@ -80,36 +80,40 @@ def asksaveasfilename( *, confirmoverwrite: bool | None = True, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., -) -> str: ... # can be empty string + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, +) -> str | tuple[()]: ... # empty string or empty tuple if cancelled, depending on the Tk version def askopenfilename( *, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., -) -> str: ... # can be empty string + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, +) -> str | tuple[()]: ... # empty string or empty tuple if cancelled, depending on the Tk version def askopenfilenames( *, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, ) -> Literal[""] | tuple[str, ...]: ... def askdirectory( - *, initialdir: StrOrBytesPath | None = ..., mustexist: bool | None = False, parent: Misc | None = ..., title: str | None = ... -) -> str: ... # can be empty string + *, + initialdir: StrOrBytesPath | None = None, + mustexist: bool | None = False, + parent: Misc | None = None, + title: str | None = None, +) -> str | tuple[()]: ... # empty string or empty tuple if cancelled, depending on the Tk version # TODO: If someone actually uses these, overload to have the actual return type of open(..., mode) def asksaveasfile( @@ -117,33 +121,33 @@ def asksaveasfile( *, confirmoverwrite: bool | None = True, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, ) -> IO[Incomplete] | None: ... def askopenfile( mode: str = "r", *, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, ) -> IO[Incomplete] | None: ... def askopenfiles( mode: str = "r", *, defaultextension: str | None = "", - filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ..., - initialdir: StrOrBytesPath | None = ..., - initialfile: StrOrBytesPath | None = ..., - parent: Misc | None = ..., - title: str | None = ..., - typevariable: StringVar | str | None = ..., + filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] = (), + initialdir: StrOrBytesPath | None = None, + initialfile: StrOrBytesPath | None = None, + parent: Misc | None = None, + title: str | None = None, + typevariable: StringVar | str | None = None, ) -> tuple[IO[Incomplete], ...]: ... # can be empty tuple def test() -> None: ... diff --git a/mypy/typeshed/stdlib/tkinter/ttk.pyi b/mypy/typeshed/stdlib/tkinter/ttk.pyi index bf184bc2e8f8..bb517d39e4e6 100644 --- a/mypy/typeshed/stdlib/tkinter/ttk.pyi +++ b/mypy/typeshed/stdlib/tkinter/ttk.pyi @@ -804,8 +804,12 @@ class Progressbar(Widget): self, master: tkinter.Misc | None = None, *, + anchor: Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] = ..., # new in Tcl/Tk 9.0 class_: str = "", cursor: tkinter._Cursor = "", + font: _FontDescription = ..., # new in Tcl/Tk 9.0 + foreground: str = ..., # new in Tcl/Tk 9.0 + justify: Literal["left", "center", "right"] = ..., # new in Tcl/Tk 9.0 length: float | str = 100, maximum: float = 100, mode: Literal["determinate", "indeterminate"] = "determinate", @@ -814,8 +818,10 @@ class Progressbar(Widget): phase: int = 0, # docs say read-only but assigning int to this works style: str = "", takefocus: bool | Literal[0, 1, ""] | Callable[[str], bool | None] = "", + text: float | str = "", # new in Tcl/Tk 9.0 value: float = 0.0, variable: tkinter.IntVar | tkinter.DoubleVar = ..., + wraplength: float | str = ..., # new in Tcl/Tk 9.0 ) -> None: ... @overload @@ -823,7 +829,11 @@ class Progressbar(Widget): self, cnf: dict[str, Any] | None = None, *, + anchor: Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] = ..., # new in Tcl/Tk 9.0 cursor: tkinter._Cursor = ..., + font: _FontDescription = ..., # new in Tcl/Tk 9.0 + foreground: str = ..., # new in Tcl/Tk 9.0 + justify: Literal["left", "center", "right"] = ..., # new in Tcl/Tk 9.0 length: float | str = ..., maximum: float = ..., mode: Literal["determinate", "indeterminate"] = ..., @@ -831,8 +841,10 @@ class Progressbar(Widget): phase: int = ..., style: str = ..., takefocus: bool | Literal[0, 1, ""] | Callable[[str], bool | None] = ..., + text: float | str = ..., # new in Tcl/Tk 9.0 value: float = ..., variable: tkinter.IntVar | tkinter.DoubleVar = ..., + wraplength: float | str = ..., # new in Tcl/Tk 9.0 ) -> dict[str, tuple[str, str, str, Any, Any]] | None: ... @overload def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ... @@ -1414,7 +1426,7 @@ class OptionMenu(Menubutton): # rest of these are keyword-only because *args syntax used above style: str = "", direction: Literal["above", "below", "left", "right", "flush"] = "below", - command: Callable[[tkinter.StringVar], object] | None = None, + command: Callable[[str], object] | None = None, name: str | None = None, ) -> None: ... else: @@ -1427,7 +1439,7 @@ class OptionMenu(Menubutton): # rest of these are keyword-only because *args syntax used above style: str = "", direction: Literal["above", "below", "left", "right", "flush"] = "below", - command: Callable[[tkinter.StringVar], object] | None = None, + command: Callable[[str], object] | None = None, ) -> None: ... # configure, config, cget, destroy are inherited from Menubutton # destroy and __setitem__ are overridden, signature does not change diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index 10561b3271c5..b8b90a0934e5 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -665,14 +665,17 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont def aclose(self) -> Coroutine[Any, Any, None]: ... +_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any) + @runtime_checkable -class Container(Protocol[_T_co]): +class Container(Protocol[_ContainerT_contra]): # This is generic more on vibes than anything else @abstractmethod - def __contains__(self, x: object, /) -> bool: ... + def __contains__(self, x: _ContainerT_contra, /) -> bool: ... @runtime_checkable -class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): +class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]): + # Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance. # Implement Sized (but don't have it as a base class). @abstractmethod def __len__(self) -> int: ... @@ -741,6 +744,7 @@ class AbstractSet(Collection[_T_co]): def __or__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ... def __sub__(self, other: AbstractSet[Any], /) -> AbstractSet[_T_co]: ... def __xor__(self, other: AbstractSet[_T], /) -> AbstractSet[_T_co | _T]: ... + def __rxor__(self, other: Iterable[_T], /) -> AbstractSet[_T_co | _T]: ... def __eq__(self, other: object, /) -> bool: ... def isdisjoint(self, other: Iterable[Any], /) -> bool: ... From ba6c0876aa5503a1ffa6e5eb3741ff54a2459942 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 18 May 2026 17:33:09 +0200 Subject: [PATCH 02/12] Adjust stubs to fix mypy lookup error due to circular dependencies in stubs --- mypy/typeshed/stdlib/__future__.pyi | 2 +- mypy/typeshed/stdlib/dis.pyi | 4 ++-- mypy/typeshed/stdlib/inspect.pyi | 4 ++-- mypy/typeshed/stdlib/itertools.pyi | 2 +- mypy/typeshed/stdlib/time.pyi | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mypy/typeshed/stdlib/__future__.pyi b/mypy/typeshed/stdlib/__future__.pyi index aa445d22bd20..a90cf1eddab7 100644 --- a/mypy/typeshed/stdlib/__future__.pyi +++ b/mypy/typeshed/stdlib/__future__.pyi @@ -1,4 +1,4 @@ -from typing import TypeAlias +from typing_extensions import TypeAlias _VersionInfo: TypeAlias = tuple[int, int, int, str, int] diff --git a/mypy/typeshed/stdlib/dis.pyi b/mypy/typeshed/stdlib/dis.pyi index 984f932e3311..0ad928934671 100644 --- a/mypy/typeshed/stdlib/dis.pyi +++ b/mypy/typeshed/stdlib/dis.pyi @@ -2,7 +2,7 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, Final, NamedTuple, TypeAlias, overload +from typing import IO, Any, Final, NamedTuple, overload from typing_extensions import Self, deprecated, disjoint_base __all__ = [ @@ -41,7 +41,7 @@ else: # Strictly this should not have to include Callable, but mypy doesn't use FunctionType # for functions (python/mypy#3171) -_HaveCodeType: TypeAlias = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] +_HaveCodeType = types.MethodType | types.FunctionType | types.CodeType | type | Callable[..., Any] if sys.version_info >= (3, 11): class Positions(NamedTuple): diff --git a/mypy/typeshed/stdlib/inspect.pyi b/mypy/typeshed/stdlib/inspect.pyi index 9bca21ab2dfd..410264820ece 100644 --- a/mypy/typeshed/stdlib/inspect.pyi +++ b/mypy/typeshed/stdlib/inspect.pyi @@ -195,8 +195,8 @@ if sys.version_info >= (3, 14): modulesbyfile: dict[str, Any] -_GetMembersPredicateTypeGuard: TypeAlias = Callable[[Any], TypeGuard[_T]] -_GetMembersPredicateTypeIs: TypeAlias = Callable[[Any], TypeIs[_T]] +_GetMembersPredicateTypeGuard = Callable[[Any], TypeGuard[_T]] +_GetMembersPredicateTypeIs = Callable[[Any], TypeIs[_T]] _GetMembersPredicate: TypeAlias = Callable[[Any], bool] _GetMembersReturn: TypeAlias = list[tuple[str, _T]] diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index d26a4e1da21e..60e79bc2e411 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -23,7 +23,7 @@ _T10 = TypeVar("_T10") _Step: TypeAlias = SupportsFloat | SupportsInt | SupportsIndex | SupportsComplex -_Predicate: TypeAlias = Callable[[_T], object] +_Predicate = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method diff --git a/mypy/typeshed/stdlib/time.pyi b/mypy/typeshed/stdlib/time.pyi index ac53089b8d82..9b5344b326ce 100644 --- a/mypy/typeshed/stdlib/time.pyi +++ b/mypy/typeshed/stdlib/time.pyi @@ -1,15 +1,15 @@ import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, final, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsFloat, SupportsIndex, TypeAlias, Union, final, type_check_only _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] if sys.version_info >= (3, 15): # anticipate on https://github.com/python/cpython/pull/139224 - _SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex + _SupportsFloatOrIndex: TypeAlias = Union[SupportsFloat, SupportsIndex] else: # before, time functions only accept (subclass of) float, *not* SupportsFloat - _SupportsFloatOrIndex: TypeAlias = float | SupportsIndex + _SupportsFloatOrIndex: TypeAlias = Union[float, SupportsIndex] altzone: int daylight: int From cab6683cf9cd1c674a0f644f56547564cb444657 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 15 Feb 2025 20:11:06 +0100 Subject: [PATCH 03/12] Partially revert Clean up argparse hacks --- mypy/typeshed/stdlib/argparse.pyi | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mypy/typeshed/stdlib/argparse.pyi b/mypy/typeshed/stdlib/argparse.pyi index da8141e235e0..2db7b8575744 100644 --- a/mypy/typeshed/stdlib/argparse.pyi +++ b/mypy/typeshed/stdlib/argparse.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsWrite, sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern -from typing import IO, Any, ClassVar, Final, Generic, Protocol, TypeAlias, TypeVar, overload, type_check_only +from typing import IO, Any, ClassVar, Final, Generic, NewType, Protocol, TypeAlias, TypeVar, overload, type_check_only from typing_extensions import Never, Self, deprecated __all__ = [ @@ -36,7 +36,9 @@ ONE_OR_MORE: Final = "+" OPTIONAL: Final = "?" PARSER: Final = "A..." REMAINDER: Final = "..." -SUPPRESS: Final = "==SUPPRESS==" +_SUPPRESS_T = NewType("_SUPPRESS_T", str) +SUPPRESS: _SUPPRESS_T | str # not using Literal because argparse sometimes compares SUPPRESS with is +# the | str is there so that foo = argparse.SUPPRESS; foo = "test" checks out in mypy ZERO_OR_MORE: Final = "*" _UNRECOGNIZED_ARGS_ATTR: Final = "_unrecognized_args" # undocumented @@ -79,7 +81,7 @@ class _ActionsContainer: # more precisely, Literal["?", "*", "+", "...", "A...", "==SUPPRESS=="], # but using this would make it hard to annotate callers that don't use a # literal argument and for subclasses to override this method. - nargs: int | str | None = None, + nargs: int | str | _SUPPRESS_T | None = None, const: Any = ..., default: Any = ..., type: _ActionType = ..., From b7dafb2a063124eb35b7435925b991beb57b9eb7 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 26 Sep 2022 12:55:07 -0700 Subject: [PATCH 04/12] Remove use of LiteralString in builtins (#13743) --- mypy/typeshed/stdlib/builtins.pyi | 130 +----------------------------- 1 file changed, 2 insertions(+), 128 deletions(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 1628f1bbf760..383b6cf89321 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -66,7 +66,7 @@ from typing import ( # noqa: Y022 # ruff: ignore[deprecated-import] # we can't import `Literal` from typing or mypy crashes: see #11247 # ruff: ignore[deprecated-import] -from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023 +from typing_extensions import Literal, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base # noqa: Y023 if sys.version_info >= (3, 14): from _typeshed import AnnotateFunc @@ -485,20 +485,8 @@ class str(Sequence[str]): def __new__(cls, object: object = "") -> Self: ... @overload def __new__(cls, object: ReadableBuffer, encoding: str = "utf-8", errors: str = "strict") -> Self: ... - - @overload - def capitalize(self: LiteralString) -> LiteralString: ... - @overload def capitalize(self) -> str: ... # type: ignore[misc] - - @overload - def casefold(self: LiteralString) -> LiteralString: ... - @overload def casefold(self) -> str: ... # type: ignore[misc] - - @overload - def center(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def center(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] def count(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... @@ -506,17 +494,9 @@ class str(Sequence[str]): def endswith( self, suffix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... - - @overload - def expandtabs(self: LiteralString, tabsize: SupportsIndex = 8) -> LiteralString: ... - @overload def expandtabs(self, tabsize: SupportsIndex = 8) -> str: ... # type: ignore[misc] def find(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... - - @overload - def format(self: LiteralString, *args: LiteralString, **kwargs: LiteralString) -> LiteralString: ... - @overload def format(self, *args: object, **kwargs: object) -> str: ... def format_map(self, mapping: _FormatMapMapping, /) -> str: ... @@ -533,119 +513,38 @@ class str(Sequence[str]): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - - @overload - def join(self: LiteralString, iterable: Iterable[LiteralString], /) -> LiteralString: ... - @overload def join(self, iterable: Iterable[str], /) -> str: ... # type: ignore[misc] - - @overload - def ljust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def ljust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] - - @overload - def lower(self: LiteralString) -> LiteralString: ... - @overload def lower(self) -> str: ... # type: ignore[misc] - - @overload - def lstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def lstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def partition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... - @overload def partition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] if sys.version_info >= (3, 13): - @overload - def replace( - self: LiteralString, old: LiteralString, new: LiteralString, /, count: SupportsIndex = -1 - ) -> LiteralString: ... - @overload def replace(self, old: str, new: str, /, count: SupportsIndex = -1) -> str: ... # type: ignore[misc] else: - @overload - def replace( - self: LiteralString, old: LiteralString, new: LiteralString, count: SupportsIndex = -1, / - ) -> LiteralString: ... - @overload def replace(self, old: str, new: str, count: SupportsIndex = -1, /) -> str: ... # type: ignore[misc] - @overload - def removeprefix(self: LiteralString, prefix: LiteralString, /) -> LiteralString: ... - @overload def removeprefix(self, prefix: str, /) -> str: ... # type: ignore[misc] - - @overload - def removesuffix(self: LiteralString, suffix: LiteralString, /) -> LiteralString: ... - @overload def removesuffix(self, suffix: str, /) -> str: ... # type: ignore[misc] def rfind(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... def rindex(self, sub: str, start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> int: ... - - @overload - def rjust(self: LiteralString, width: SupportsIndex, fillchar: LiteralString = " ", /) -> LiteralString: ... - @overload def rjust(self, width: SupportsIndex, fillchar: str = " ", /) -> str: ... # type: ignore[misc] - - @overload - def rpartition(self: LiteralString, sep: LiteralString, /) -> tuple[LiteralString, LiteralString, LiteralString]: ... - @overload def rpartition(self, sep: str, /) -> tuple[str, str, str]: ... # type: ignore[misc] - - @overload - def rsplit(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... - @overload def rsplit(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] - - @overload - def rstrip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def rstrip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def split(self: LiteralString, sep: LiteralString | None = None, maxsplit: SupportsIndex = -1) -> list[LiteralString]: ... - @overload def split(self, sep: str | None = None, maxsplit: SupportsIndex = -1) -> list[str]: ... # type: ignore[misc] - - @overload - def splitlines(self: LiteralString, keepends: bool = False) -> list[LiteralString]: ... - @overload def splitlines(self, keepends: bool = False) -> list[str]: ... # type: ignore[misc] def startswith( self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, / ) -> bool: ... - - @overload - def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString: ... - @overload def strip(self, chars: str | None = None, /) -> str: ... # type: ignore[misc] - - @overload - def swapcase(self: LiteralString) -> LiteralString: ... - @overload def swapcase(self) -> str: ... # type: ignore[misc] - - @overload - def title(self: LiteralString) -> LiteralString: ... - @overload def title(self) -> str: ... # type: ignore[misc] def translate(self, table: _TranslateTable, /) -> str: ... - - @overload - def upper(self: LiteralString) -> LiteralString: ... - @overload def upper(self) -> str: ... # type: ignore[misc] - - @overload - def zfill(self: LiteralString, width: SupportsIndex, /) -> LiteralString: ... - @overload def zfill(self, width: SupportsIndex, /) -> str: ... # type: ignore[misc] if sys.version_info >= (3, 15): @@ -673,51 +572,26 @@ class str(Sequence[str]): @staticmethod @overload def maketrans(x: str, y: str, z: str, /) -> dict[int, int | None]: ... - - @overload - def __add__(self: LiteralString, value: LiteralString, /) -> LiteralString: ... - @overload def __add__(self, value: str, /) -> str: ... # type: ignore[misc] # Incompatible with Sequence.__contains__ def __contains__(self, key: str, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __ge__(self, value: str, /) -> bool: ... - - @overload - def __getitem__(self: LiteralString, key: SupportsIndex | slice[SupportsIndex | None], /) -> LiteralString: ... - @overload def __getitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> str: ... # type: ignore[misc] def __gt__(self, value: str, /) -> bool: ... def __hash__(self) -> int: ... - - @overload - def __iter__(self: LiteralString) -> Iterator[LiteralString]: ... - @overload def __iter__(self) -> Iterator[str]: ... # type: ignore[misc] def __le__(self, value: str, /) -> bool: ... def __len__(self) -> int: ... def __lt__(self, value: str, /) -> bool: ... - - @overload - def __mod__(self: LiteralString, value: LiteralString | tuple[LiteralString, ...], /) -> LiteralString: ... - @overload - def __mod__(self, value: object, /) -> str: ... - + def __mod__(self, value: Any, /) -> str: ... def __rmod__(self, value: str, /) -> str: ... - - @overload - def __mul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... - @overload def __mul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __ne__(self, value: object, /) -> bool: ... - - @overload - def __rmul__(self: LiteralString, value: SupportsIndex, /) -> LiteralString: ... - @overload def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... From 4c1711289799fba03f2e43b50705f627c08a820a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:36:38 +0100 Subject: [PATCH 05/12] Revert Remove redundant inheritances from Iterator in builtins --- mypy/typeshed/stdlib/_asyncio.pyi | 4 +- mypy/typeshed/stdlib/builtins.pyi | 10 ++--- mypy/typeshed/stdlib/csv.pyi | 4 +- mypy/typeshed/stdlib/fileinput.pyi | 6 +-- mypy/typeshed/stdlib/itertools.pyi | 38 +++++++++---------- mypy/typeshed/stdlib/multiprocessing/pool.pyi | 4 +- mypy/typeshed/stdlib/sqlite3/__init__.pyi | 2 +- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/mypy/typeshed/stdlib/_asyncio.pyi b/mypy/typeshed/stdlib/_asyncio.pyi index 641c152d985b..386a96f38abd 100644 --- a/mypy/typeshed/stdlib/_asyncio.pyi +++ b/mypy/typeshed/stdlib/_asyncio.pyi @@ -1,6 +1,6 @@ import sys from asyncio.events import AbstractEventLoop -from collections.abc import Awaitable, Callable, Coroutine, Generator +from collections.abc import Awaitable, Callable, Coroutine, Generator, Iterable from contextvars import Context from types import FrameType, GenericAlias from typing import Any, Literal, TextIO, TypeAlias, TypeVar @@ -11,7 +11,7 @@ _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None @disjoint_base -class Future(Awaitable[_T]): +class Future(Awaitable[_T], Iterable[_T]): _state: str @property def _exception(self) -> BaseException | None: ... diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index 383b6cf89321..edf33c00dccc 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -1423,7 +1423,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class enumerate(Generic[_T]): +class enumerate(Iterator[tuple[int, _T]]): def __new__(cls, iterable: Iterable[_T], start: int = 0) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> tuple[int, _T]: ... @@ -1689,7 +1689,7 @@ else: exit: _sitebuiltins.Quitter @disjoint_base -class filter(Generic[_T]): +class filter(Iterator[_T]): @overload def __new__(cls, function: None, iterable: Iterable[_T | None], /) -> Self: ... @overload @@ -1760,7 +1760,7 @@ license: _sitebuiltins._Printer def locals() -> dict[str, Any]: ... @disjoint_base -class map(Generic[_S]): +class map(Iterator[_S]): # 3.14 adds `strict` argument. if sys.version_info >= (3, 14): @overload @@ -2080,7 +2080,7 @@ class _SupportsReversed(Protocol[_T_co]): def __reversed__(self) -> _T_co: ... @disjoint_base -class reversed(Generic[_T_co]): +class reversed(Iterator[_T_co]): @overload def __new__(cls, sequence: _SupportsReversed[_T], /) -> _T: ... # type: ignore[misc] @overload @@ -2160,7 +2160,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: ... def vars(object: Any = ..., /) -> dict[str, Any]: ... @disjoint_base -class zip(Generic[_T_co]): +class zip(Iterator[_T_co]): @overload def __new__(cls, *, strict: bool = False) -> zip[Any]: ... @overload diff --git a/mypy/typeshed/stdlib/csv.pyi b/mypy/typeshed/stdlib/csv.pyi index 751e85566f88..18b36b20160f 100644 --- a/mypy/typeshed/stdlib/csv.pyi +++ b/mypy/typeshed/stdlib/csv.pyi @@ -21,7 +21,7 @@ if sys.version_info >= (3, 12): from _csv import QUOTE_NOTNULL as QUOTE_NOTNULL, QUOTE_STRINGS as QUOTE_STRINGS from _csv import Reader, Writer from _typeshed import SupportsWrite -from collections.abc import Collection, Iterable, Mapping, Sequence +from collections.abc import Collection, Iterable, Iterator, Mapping, Sequence from types import GenericAlias from typing import Any, Generic, Literal, TypeVar, overload from typing_extensions import Self @@ -73,7 +73,7 @@ class excel(Dialect): ... class excel_tab(excel): ... class unix_dialect(Dialect): ... -class DictReader(Generic[_T]): +class DictReader(Iterator[dict[_T | Any, str | Any]], Generic[_T]): fieldnames: Sequence[_T] | None restkey: _T | None restval: str | Any | None diff --git a/mypy/typeshed/stdlib/fileinput.pyi b/mypy/typeshed/stdlib/fileinput.pyi index 37783254c70f..db9c228f5f28 100644 --- a/mypy/typeshed/stdlib/fileinput.pyi +++ b/mypy/typeshed/stdlib/fileinput.pyi @@ -1,8 +1,8 @@ import sys from _typeshed import AnyStr_co, StrOrBytesPath -from collections.abc import Callable, Iterable +from collections.abc import Callable, Iterable, Iterator from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeAlias, overload, type_check_only +from typing import IO, Any, AnyStr, Literal, Protocol, TypeAlias, overload, type_check_only from typing_extensions import Self, deprecated __all__ = [ @@ -74,7 +74,7 @@ def fileno() -> int: ... def isfirstline() -> bool: ... def isstdin() -> bool: ... -class FileInput(Generic[AnyStr]): +class FileInput(Iterator[AnyStr]): # encoding and errors are added @overload def __init__( diff --git a/mypy/typeshed/stdlib/itertools.pyi b/mypy/typeshed/stdlib/itertools.pyi index 60e79bc2e411..fd7daf11e808 100644 --- a/mypy/typeshed/stdlib/itertools.pyi +++ b/mypy/typeshed/stdlib/itertools.pyi @@ -28,7 +28,7 @@ _Predicate = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method @disjoint_base -class count(Generic[_N]): +class count(Iterator[_N]): @overload def __new__(cls) -> count[int]: ... @overload @@ -40,13 +40,13 @@ class count(Generic[_N]): def __iter__(self) -> Self: ... @disjoint_base -class cycle(Generic[_T]): +class cycle(Iterator[_T]): def __new__(cls, iterable: Iterable[_T], /) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @disjoint_base -class repeat(Generic[_T]): +class repeat(Iterator[_T]): @overload def __new__(cls, object: _T) -> Self: ... @overload @@ -57,7 +57,7 @@ class repeat(Generic[_T]): def __length_hint__(self) -> int: ... @disjoint_base -class accumulate(Generic[_T]): +class accumulate(Iterator[_T]): @overload def __new__(cls, iterable: Iterable[_T], func: None = None, *, initial: _T | None = None) -> Self: ... @overload @@ -67,7 +67,7 @@ class accumulate(Generic[_T]): def __next__(self) -> _T: ... @disjoint_base -class chain(Generic[_T]): +class chain(Iterator[_T]): def __new__(cls, *iterables: Iterable[_T]) -> Self: ... def __next__(self) -> _T: ... def __iter__(self) -> Self: ... @@ -77,25 +77,25 @@ class chain(Generic[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... @disjoint_base -class compress(Generic[_T]): +class compress(Iterator[_T]): def __new__(cls, data: Iterable[_T], selectors: Iterable[Any]) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class dropwhile(Generic[_T]): +class dropwhile(Iterator[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class filterfalse(Generic[_T]): +class filterfalse(Iterator[_T]): def __new__(cls, function: _Predicate[_T] | None, iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @disjoint_base -class groupby(Generic[_T_co, _S_co]): +class groupby(Iterator[tuple[_T_co, Iterator[_S_co]]], Generic[_T_co, _S_co]): @overload def __new__(cls, iterable: Iterable[_T1], key: None = None) -> groupby[_T1, _T1]: ... @overload @@ -105,7 +105,7 @@ class groupby(Generic[_T_co, _S_co]): def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: ... @disjoint_base -class islice(Generic[_T]): +class islice(Iterator[_T]): @overload def __new__(cls, iterable: Iterable[_T], stop: int | None, /) -> Self: ... @overload @@ -115,13 +115,13 @@ class islice(Generic[_T]): def __next__(self) -> _T: ... @disjoint_base -class starmap(Generic[_T_co]): +class starmap(Iterator[_T_co]): def __new__(cls, function: Callable[..., _T], iterable: Iterable[Iterable[Any]], /) -> starmap[_T]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... @disjoint_base -class takewhile(Generic[_T]): +class takewhile(Iterator[_T]): def __new__(cls, predicate: _Predicate[_T], iterable: Iterable[_T], /) -> Self: ... def __iter__(self) -> Self: ... def __next__(self) -> _T: ... @@ -129,7 +129,7 @@ class takewhile(Generic[_T]): def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: ... @disjoint_base -class zip_longest(Generic[_T_co]): +class zip_longest(Iterator[_T_co]): # one iterable (fillvalue doesn't matter) @overload def __new__(cls, iter1: Iterable[_T1], /, *, fillvalue: object = None) -> zip_longest[tuple[_T1]]: ... @@ -209,7 +209,7 @@ class zip_longest(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class product(Generic[_T_co]): +class product(Iterator[_T_co]): @overload def __new__(cls, iter1: Iterable[_T1], /) -> product[tuple[_T1]]: ... @overload @@ -296,7 +296,7 @@ class product(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class permutations(Generic[_T_co]): +class permutations(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> permutations[tuple[_T, _T]]: ... @overload @@ -312,7 +312,7 @@ class permutations(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations(Generic[_T_co]): +class combinations(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations[tuple[_T, _T]]: ... @overload @@ -328,7 +328,7 @@ class combinations(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class combinations_with_replacement(Generic[_T_co]): +class combinations_with_replacement(Iterator[_T_co]): @overload def __new__(cls, iterable: Iterable[_T], r: Literal[2]) -> combinations_with_replacement[tuple[_T, _T]]: ... @overload @@ -344,14 +344,14 @@ class combinations_with_replacement(Generic[_T_co]): def __next__(self) -> _T_co: ... @disjoint_base -class pairwise(Generic[_T_co]): +class pairwise(Iterator[_T_co]): def __new__(cls, iterable: Iterable[_T], /) -> pairwise[tuple[_T, _T]]: ... def __iter__(self) -> Self: ... def __next__(self) -> _T_co: ... if sys.version_info >= (3, 12): @disjoint_base - class batched(Generic[_T_co]): + class batched(Iterator[_T_co], Generic[_T_co]): if sys.version_info >= (3, 13): @overload def __new__(cls, iterable: Iterable[_T], n: Literal[1], *, strict: Literal[True]) -> batched[tuple[_T]]: ... diff --git a/mypy/typeshed/stdlib/multiprocessing/pool.pyi b/mypy/typeshed/stdlib/multiprocessing/pool.pyi index 5642e50d0e76..203c5887ca7e 100644 --- a/mypy/typeshed/stdlib/multiprocessing/pool.pyi +++ b/mypy/typeshed/stdlib/multiprocessing/pool.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable, Iterable, Mapping +from collections.abc import Callable, Iterable, Iterator, Mapping from multiprocessing.context import DefaultContext, Process as _Process from types import GenericAlias, TracebackType from typing import Any, Final, Generic, TypeVar @@ -32,7 +32,7 @@ class MapResult(ApplyResult[list[_T]]): error_callback: Callable[[BaseException], object] | None, ) -> None: ... -class IMapIterator(Generic[_T]): +class IMapIterator(Iterator[_T]): def __init__(self, pool: Pool) -> None: ... def __iter__(self) -> Self: ... def next(self, timeout: float | None = None) -> _T: ... diff --git a/mypy/typeshed/stdlib/sqlite3/__init__.pyi b/mypy/typeshed/stdlib/sqlite3/__init__.pyi index 80a02079dd05..d1065a509af5 100644 --- a/mypy/typeshed/stdlib/sqlite3/__init__.pyi +++ b/mypy/typeshed/stdlib/sqlite3/__init__.pyi @@ -437,7 +437,7 @@ class Connection: ) -> Literal[False]: ... @disjoint_base -class Cursor: +class Cursor(Iterator[Any]): arraysize: int @property def connection(self) -> Connection: ... From f17c005d954198e6fe88008628b7cad2497af956 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:00:18 +0100 Subject: [PATCH 06/12] Revert Use contravariant type variable in Container --- mypy/typeshed/stdlib/typing.pyi | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mypy/typeshed/stdlib/typing.pyi b/mypy/typeshed/stdlib/typing.pyi index b8b90a0934e5..0ea21c5dd7f1 100644 --- a/mypy/typeshed/stdlib/typing.pyi +++ b/mypy/typeshed/stdlib/typing.pyi @@ -665,17 +665,14 @@ class AsyncGenerator(AsyncIterator[_YieldT_co], Protocol[_YieldT_co, _SendT_cont def aclose(self) -> Coroutine[Any, Any, None]: ... -_ContainerT_contra = TypeVar("_ContainerT_contra", contravariant=True, default=Any) - @runtime_checkable -class Container(Protocol[_ContainerT_contra]): +class Container(Protocol[_T_co]): # This is generic more on vibes than anything else @abstractmethod - def __contains__(self, x: _ContainerT_contra, /) -> bool: ... + def __contains__(self, x: object, /) -> bool: ... @runtime_checkable -class Collection(Iterable[_T_co], Container[Any], Protocol[_T_co]): - # Note: need to use Container[Any] instead of Container[_T_co] to ensure covariance. +class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): # Implement Sized (but don't have it as a base class). @abstractmethod def __len__(self) -> int: ... From 31051d26e0109b3ba35cb65ca8a550ec8594e9e0 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Wed, 6 May 2026 19:49:41 -0700 Subject: [PATCH 07/12] Revert operator changes --- mypy/typeshed/stdlib/_operator.pyi | 59 +++++++----------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/mypy/typeshed/stdlib/_operator.pyi b/mypy/typeshed/stdlib/_operator.pyi index 565bb41697f1..ff419842ebfc 100644 --- a/mypy/typeshed/stdlib/_operator.pyi +++ b/mypy/typeshed/stdlib/_operator.pyi @@ -1,16 +1,5 @@ import sys -from _typeshed import ( - ReadableBuffer, - SupportsAdd, - SupportsGetItem, - SupportsMod, - SupportsMul, - SupportsRAdd, - SupportsRMod, - SupportsRMul, - SupportsRSub, - SupportsSub, -) +from _typeshed import ReadableBuffer, SupportsGetItem from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller from typing import Any, ParamSpec, Protocol, SupportsAbs, SupportsIndex, TypeAlias, TypeVar, overload, type_check_only @@ -19,7 +8,6 @@ from typing_extensions import TypeIs _R = TypeVar("_R") _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) -_T_contra = TypeVar("_T_contra", contravariant=True) _K = TypeVar("_K") _V = TypeVar("_V") _P = ParamSpec("_P") @@ -70,43 +58,24 @@ def truth(a: object, /) -> bool: ... def is_(a: object, b: object, /) -> bool: ... def is_not(a: object, b: object, /) -> bool: ... def abs(a: SupportsAbs[_T], /) -> _T: ... - -@overload -def add(a: SupportsAdd[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def add(a: _T_contra, b: SupportsRAdd[_T_contra, _T_co], /) -> _T_co: ... - -def and_(a, b, /): ... -def floordiv(a, b, /): ... +def add(a: Any, b: Any, /) -> Any: ... +def and_(a: Any, b: Any, /) -> Any: ... +def floordiv(a: Any, b: Any, /) -> Any: ... def index(a: SupportsIndex, /) -> int: ... def inv(a: _SupportsInversion[_T_co], /) -> _T_co: ... def invert(a: _SupportsInversion[_T_co], /) -> _T_co: ... -def lshift(a, b, /): ... - -@overload -def mod(a: SupportsMod[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def mod(a: _T_contra, b: SupportsRMod[_T_contra, _T_co], /) -> _T_co: ... - -@overload -def mul(a: SupportsMul[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def mul(a: _T_contra, b: SupportsRMul[_T_contra, _T_co], /) -> _T_co: ... - -def matmul(a, b, /): ... +def lshift(a: Any, b: Any, /) -> Any: ... +def mod(a: Any, b: Any, /) -> Any: ... +def mul(a: Any, b: Any, /) -> Any: ... +def matmul(a: Any, b: Any, /) -> Any: ... def neg(a: _SupportsNeg[_T_co], /) -> _T_co: ... -def or_(a, b, /): ... +def or_(a: Any, b: Any, /) -> Any: ... def pos(a: _SupportsPos[_T_co], /) -> _T_co: ... -def pow(a, b, /): ... -def rshift(a, b, /): ... - -@overload -def sub(a: SupportsSub[_T_contra, _T_co], b: _T_contra, /) -> _T_co: ... -@overload -def sub(a: _T_contra, b: SupportsRSub[_T_contra, _T_co], /) -> _T_co: ... - -def truediv(a, b, /): ... -def xor(a, b, /): ... +def pow(a: Any, b: Any, /) -> Any: ... +def rshift(a: Any, b: Any, /) -> Any: ... +def sub(a: Any, b: Any, /) -> Any: ... +def truediv(a: Any, b: Any, /) -> Any: ... +def xor(a: Any, b: Any, /) -> Any: ... def concat(a: Sequence[_T], b: Sequence[_T], /) -> Sequence[_T]: ... def contains(a: Container[object], b: object, /) -> bool: ... def countOf(a: Iterable[object], b: object, /) -> int: ... From 8c68e509f222afdef21ce4ada95f4d31de131cac Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Sat, 29 Oct 2022 12:47:21 -0700 Subject: [PATCH 08/12] Revert sum literal integer change (#13961) This is allegedly causing large performance problems, see 13821 typeshed/8231 had zero hits on mypy_primer, so it's not the worst thing to undo. Patching this in typeshed also feels weird, since there's a more general soundness issue. If a typevar has a bound or constraint, we might not want to solve it to a Literal. If we can confirm the performance regression or fix the unsoundness within mypy, I might pursue upstreaming this in typeshed. (Reminder: add this to the sync_typeshed script once merged) --- mypy/typeshed/stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy/typeshed/stdlib/builtins.pyi b/mypy/typeshed/stdlib/builtins.pyi index edf33c00dccc..e5890b5025ef 100644 --- a/mypy/typeshed/stdlib/builtins.pyi +++ b/mypy/typeshed/stdlib/builtins.pyi @@ -2146,7 +2146,7 @@ _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWit # without creating many false-positive errors (see #7578). # Instead, we special-case the most common examples of this: bool and literal integers. @overload -def sum(iterable: Iterable[bool | _LiteralInteger], /, start: int = 0) -> int: ... +def sum(iterable: Iterable[bool], /, start: int = 0) -> int: ... @overload def sum(iterable: Iterable[_SupportsSumNoDefaultT], /) -> _SupportsSumNoDefaultT | Literal[0]: ... @overload From 9bffbfa86043a468ef9f8a1746641e20269d867a Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 1 May 2023 20:34:55 +0100 Subject: [PATCH 09/12] Revert typeshed ctypes change The plugin provides superior type checking: https://github.com/python/mypy/pull/13987#issuecomment-1310863427 A manual cherry-pick of e437cdf. --- mypy/typeshed/stdlib/_ctypes.pyi | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mypy/typeshed/stdlib/_ctypes.pyi b/mypy/typeshed/stdlib/_ctypes.pyi index 83ac60fd0d42..45cf0e9bad57 100644 --- a/mypy/typeshed/stdlib/_ctypes.pyi +++ b/mypy/typeshed/stdlib/_ctypes.pyi @@ -324,12 +324,7 @@ class Array(_CData, Generic[_CT], metaclass=_PyCArrayType): @_type_.setter def _type_(self, value: type[_CT]) -> None: ... - # Note: only available if _CT == c_char - @property - def raw(self) -> bytes: ... - @raw.setter - def raw(self, value: ReadableBuffer) -> None: ... - + raw: bytes # Note: only available if _CT == c_char value: Any # Note: bytes if _CT == c_char, str if _CT == c_wchar, unavailable otherwise # TODO: These methods cannot be annotated correctly at the moment. # All of these "Any"s stand for the array's element type, but it's not possible to use _CT From 4adc5945644dd13c7b548d47e29e4bdfe477d57d Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sun, 22 Feb 2026 20:37:48 -0800 Subject: [PATCH 10/12] Temporarily revert contextlib deprecation --- mypy/typeshed/stdlib/contextlib.pyi | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/mypy/typeshed/stdlib/contextlib.pyi b/mypy/typeshed/stdlib/contextlib.pyi index c286514af229..461965f3868d 100644 --- a/mypy/typeshed/stdlib/contextlib.pyi +++ b/mypy/typeshed/stdlib/contextlib.pyi @@ -5,7 +5,7 @@ from abc import ABC, abstractmethod from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Iterator from types import TracebackType from typing import Any, Generic, ParamSpec, Protocol, TypeAlias, TypeVar, overload, runtime_checkable, type_check_only -from typing_extensions import Self, deprecated +from typing_extensions import Self __all__ = [ "aclosing", @@ -84,12 +84,6 @@ class _GeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -@overload -def contextmanager(func: Callable[_P, Generator[_T_co, None, object]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... -@overload -@deprecated( - "Annotating the return type as `-> Iterator[Foo]` with `@contextmanager` is deprecated. Use `-> Generator[Foo]` instead." -) def contextmanager(func: Callable[_P, Iterator[_T_co]]) -> Callable[_P, _GeneratorContextManager[_T_co]]: ... _AF = TypeVar("_AF", bound=Callable[..., Awaitable[Any]]) @@ -107,13 +101,6 @@ class _AsyncGeneratorContextManager( self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None ) -> bool | None: ... -@overload -def asynccontextmanager(func: Callable[_P, AsyncGenerator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... -@overload -@deprecated( - "Annotating the return type as `-> AsyncIterator[Foo]` with `@asynccontextmanager` is deprecated. " - "Use `-> AsyncGenerator[Foo]` instead." -) def asynccontextmanager(func: Callable[_P, AsyncIterator[_T_co]]) -> Callable[_P, _AsyncGeneratorContextManager[_T_co]]: ... @type_check_only From 330050e2b6652485d0b63e71b1f69b57fc1f56e7 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:10:43 +0100 Subject: [PATCH 11/12] Add patch to revert datetime generic change --- ...evert-datetime-generic-tzinfo-change.patch | 302 ++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 misc/typeshed_patches/0001-Revert-datetime-generic-tzinfo-change.patch diff --git a/misc/typeshed_patches/0001-Revert-datetime-generic-tzinfo-change.patch b/misc/typeshed_patches/0001-Revert-datetime-generic-tzinfo-change.patch new file mode 100644 index 000000000000..9edb9625f717 --- /dev/null +++ b/misc/typeshed_patches/0001-Revert-datetime-generic-tzinfo-change.patch @@ -0,0 +1,302 @@ +From cecd8a28f320ae88ea25387ed3d23c8b3b189486 Mon Sep 17 00:00:00 2001 +From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> +Date: Thu, 5 Nov 2026 13:08:55 +0100 +Subject: [PATCH] Revert datetime generic tzinfo change + +--- + mypy/typeshed/stdlib/datetime.pyi | 213 ++++-------------------------- + 1 file changed, 25 insertions(+), 188 deletions(-) + +diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi +index 5272e3850..0a21f72b0 100644 +--- a/mypy/typeshed/stdlib/datetime.pyi ++++ b/mypy/typeshed/stdlib/datetime.pyi +@@ -1,7 +1,7 @@ + import sys + from abc import abstractmethod + from time import struct_time +-from typing import Any, ClassVar, Final, Generic, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only ++from typing import ClassVar, Final, SupportsIndex, TypeAlias, final, overload, type_check_only + from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base + + if sys.version_info >= (3, 11): +@@ -266,28 +266,10 @@ class timedelta: + def __bool__(self) -> bool: ... + def __hash__(self) -> int: ... + +-_TzInfoT = TypeVar("_TzInfoT", bound=tzinfo | None, default=Any) +- + @disjoint_base +-class datetime(date, Generic[_TzInfoT]): +- min: ClassVar[datetime[None]] +- max: ClassVar[datetime[None]] +- +- @overload +- def __new__( +- cls, +- year: SupportsIndex, +- month: SupportsIndex, +- day: SupportsIndex, +- hour: SupportsIndex = 0, +- minute: SupportsIndex = 0, +- second: SupportsIndex = 0, +- microsecond: SupportsIndex = 0, +- tzinfo: None = None, +- *, +- fold: int = 0, +- ) -> datetime[None]: ... +- @overload ++class datetime(date): ++ min: ClassVar[datetime] ++ max: ClassVar[datetime] + def __new__( + cls, + year: SupportsIndex, +@@ -297,25 +279,10 @@ class datetime(date, Generic[_TzInfoT]): + minute: SupportsIndex = 0, + second: SupportsIndex = 0, + microsecond: SupportsIndex = 0, +- *, +- tzinfo: _TzInfo, +- fold: int = 0, +- ) -> datetime[_TzInfo]: ... +- @overload +- def __new__( +- cls, +- year: SupportsIndex, +- month: SupportsIndex, +- day: SupportsIndex, +- hour: SupportsIndex, +- minute: SupportsIndex, +- second: SupportsIndex, +- microsecond: SupportsIndex, +- tzinfo: _TzInfo, ++ tzinfo: _TzInfo | None = None, + *, + fold: int = 0, +- ) -> datetime[_TzInfo]: ... +- ++ ) -> Self: ... + @property + def hour(self) -> int: ... + @property +@@ -325,64 +292,32 @@ class datetime(date, Generic[_TzInfoT]): + @property + def microsecond(self) -> int: ... + @property +- def tzinfo(self) -> _TzInfoT: ... ++ def tzinfo(self) -> _TzInfo | None: ... + @property + def fold(self) -> int: ... + # On <3.12, the name of the first parameter in the pure-Python implementation + # didn't match the name in the C implementation, + # meaning it is only *safe* to pass it as a keyword argument on 3.12+ + if sys.version_info >= (3, 12): +- @overload # type: ignore[override] +- @classmethod +- def fromtimestamp(cls, timestamp: float, tz: None = None) -> datetime[None]: ... +- @overload + @classmethod +- def fromtimestamp(cls, timestamp: float, tz: _TzInfo) -> datetime[_TzInfo]: ... +- @overload +- @classmethod +- def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... +- else: +- @overload # type: ignore[override] +- @classmethod +- def fromtimestamp(cls, timestamp: float, /, tz: None = None) -> datetime[None]: ... +- @overload +- @classmethod +- def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo) -> datetime[_TzInfo]: ... +- @overload +- @classmethod +- def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... +- +- # fromisoformat returns Self, but we can't specialize "Self" +- if sys.version_info >= (3, 15): +- @classmethod +- def fromisoformat(cls, string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] ++ def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = None) -> Self: ... + else: + @classmethod +- def fromisoformat(cls, date_string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] +- +- @classmethod +- @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.UTC)") +- def utcfromtimestamp(cls, t: float, /) -> datetime[None]: ... +- +- @overload +- @classmethod +- def now(cls, tz: None = None) -> datetime[None]: ... +- @overload +- @classmethod +- def now(cls, tz: _TzInfo) -> datetime[_TzInfo]: ... ++ def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None = None) -> Self: ... + + @classmethod +- def today(cls) -> datetime[None]: ... # type: ignore[override] ++ @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.timezone.utc)") ++ def utcfromtimestamp(cls, t: float, /) -> Self: ... + @classmethod +- @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") +- def utcnow(cls) -> datetime[None]: ... +- +- @overload ++ def now(cls, tz: _TzInfo | None = None) -> Self: ... + @classmethod +- def combine(cls, date: _Date, time: _Time, tzinfo: None = None) -> datetime[None]: ... +- @overload ++ @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.timezone.utc)") ++ def utcnow(cls) -> Self: ... + @classmethod +- def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo) -> datetime[_TzInfo]: ... ++ def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ... ++ if sys.version_info >= (3, 15): ++ @classmethod ++ def fromisoformat(cls, string: str, /) -> Self: ... + + def timestamp(self) -> float: ... + def utctimetuple(self) -> struct_time: ... +@@ -405,7 +340,6 @@ class datetime(date, Generic[_TzInfoT]): + fold: int = ..., + ) -> Self: ... + +- @overload + def replace( + self, + year: SupportsIndex = ..., +@@ -415,67 +349,11 @@ class datetime(date, Generic[_TzInfoT]): + minute: SupportsIndex = ..., + second: SupportsIndex = ..., + microsecond: SupportsIndex = ..., ++ tzinfo: _TzInfo | None = ..., + *, + fold: int = ..., + ) -> Self: ... +- @overload +- def replace( +- self, +- year: SupportsIndex, +- month: SupportsIndex, +- day: SupportsIndex, +- hour: SupportsIndex, +- minute: SupportsIndex, +- second: SupportsIndex, +- microsecond: SupportsIndex, +- tzinfo: _TzInfo, +- *, +- fold: int = ..., +- ) -> datetime[_TzInfo]: ... +- @overload +- def replace( +- self, +- year: SupportsIndex = ..., +- month: SupportsIndex = ..., +- day: SupportsIndex = ..., +- hour: SupportsIndex = ..., +- minute: SupportsIndex = ..., +- second: SupportsIndex = ..., +- microsecond: SupportsIndex = ..., +- *, +- tzinfo: _TzInfo, +- fold: int = ..., +- ) -> datetime[_TzInfo]: ... +- @overload +- def replace( +- self, +- year: SupportsIndex, +- month: SupportsIndex, +- day: SupportsIndex, +- hour: SupportsIndex, +- minute: SupportsIndex, +- second: SupportsIndex, +- microsecond: SupportsIndex, +- tzinfo: None, +- *, +- fold: int = ..., +- ) -> datetime[None]: ... +- @overload +- def replace( +- self, +- year: SupportsIndex = ..., +- month: SupportsIndex = ..., +- day: SupportsIndex = ..., +- hour: SupportsIndex = ..., +- minute: SupportsIndex = ..., +- second: SupportsIndex = ..., +- microsecond: SupportsIndex = ..., +- *, +- tzinfo: None, +- fold: int = ..., +- ) -> datetime[None]: ... +- +- def astimezone(self, tz: _TzInfo | None = None) -> datetime[_TzInfo]: ... ++ def astimezone(self, tz: _TzInfo | None = None) -> Self: ... + def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: ... + + if sys.version_info >= (3, 15): +@@ -488,56 +366,15 @@ class datetime(date, Generic[_TzInfoT]): + def utcoffset(self) -> timedelta | None: ... + def tzname(self) -> str | None: ... + def dst(self) -> timedelta | None: ... +- +- @overload # type: ignore[override] +- def __le__( # type: ignore[overload-overlap] +- self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / +- ) -> bool: ... # type: ignore[misc] +- @overload +- def __le__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] +- @overload +- def __le__(self: datetime[Any], value: datetime[Any], /) -> Never: ... +- +- @overload # type: ignore[override] +- def __lt__( # type: ignore[overload-overlap] +- self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / +- ) -> bool: ... # type: ignore[misc] +- @overload +- def __lt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] +- @overload +- def __lt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... +- +- @overload # type: ignore[override] +- def __ge__( # type: ignore[overload-overlap] +- self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / +- ) -> bool: ... # type: ignore[misc] +- @overload +- def __ge__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] +- @overload +- def __ge__(self: datetime[Any], value: datetime[Any], /) -> Never: ... +- +- @overload # type: ignore[override] +- def __gt__( # type: ignore[overload-overlap] +- self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / +- ) -> bool: ... # type: ignore[misc] +- @overload +- def __gt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] +- @overload +- def __gt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... +- ++ def __le__(self, value: datetime, /) -> bool: ... # type: ignore[override] ++ def __lt__(self, value: datetime, /) -> bool: ... # type: ignore[override] ++ def __ge__(self, value: datetime, /) -> bool: ... # type: ignore[override] ++ def __gt__(self, value: datetime, /) -> bool: ... # type: ignore[override] + def __eq__(self, value: object, /) -> bool: ... + def __hash__(self) -> int: ... + + @overload # type: ignore[override] +- def __sub__( # type: ignore[overload-overlap] +- self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / +- ) -> timedelta: ... +- @overload +- def __sub__( # type: ignore[overload-overlap] +- self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], / +- ) -> timedelta: ... +- @overload +- def __sub__(self: datetime[Any], value: datetime[Any], /) -> Never: ... ++ def __sub__(self, value: Self, /) -> timedelta: ... + @overload + def __sub__(self, value: timedelta, /) -> Self: ... + +-- +2.56.0 + From 5c562af2e35b73af9ac732d9540286bfeeb704c8 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 5 Nov 2026 13:12:28 +0100 Subject: [PATCH 12/12] Revert datetime generic tzinfo change --- mypy/typeshed/stdlib/datetime.pyi | 213 ++++-------------------------- 1 file changed, 25 insertions(+), 188 deletions(-) diff --git a/mypy/typeshed/stdlib/datetime.pyi b/mypy/typeshed/stdlib/datetime.pyi index 5272e3850fe7..0a21f72b09de 100644 --- a/mypy/typeshed/stdlib/datetime.pyi +++ b/mypy/typeshed/stdlib/datetime.pyi @@ -1,7 +1,7 @@ import sys from abc import abstractmethod from time import struct_time -from typing import Any, ClassVar, Final, Generic, SupportsIndex, TypeAlias, TypeVar, final, overload, type_check_only +from typing import ClassVar, Final, SupportsIndex, TypeAlias, final, overload, type_check_only from typing_extensions import CapsuleType, Never, Self, deprecated, disjoint_base if sys.version_info >= (3, 11): @@ -266,28 +266,10 @@ class timedelta: def __bool__(self) -> bool: ... def __hash__(self) -> int: ... -_TzInfoT = TypeVar("_TzInfoT", bound=tzinfo | None, default=Any) - @disjoint_base -class datetime(date, Generic[_TzInfoT]): - min: ClassVar[datetime[None]] - max: ClassVar[datetime[None]] - - @overload - def __new__( - cls, - year: SupportsIndex, - month: SupportsIndex, - day: SupportsIndex, - hour: SupportsIndex = 0, - minute: SupportsIndex = 0, - second: SupportsIndex = 0, - microsecond: SupportsIndex = 0, - tzinfo: None = None, - *, - fold: int = 0, - ) -> datetime[None]: ... - @overload +class datetime(date): + min: ClassVar[datetime] + max: ClassVar[datetime] def __new__( cls, year: SupportsIndex, @@ -297,25 +279,10 @@ class datetime(date, Generic[_TzInfoT]): minute: SupportsIndex = 0, second: SupportsIndex = 0, microsecond: SupportsIndex = 0, - *, - tzinfo: _TzInfo, - fold: int = 0, - ) -> datetime[_TzInfo]: ... - @overload - def __new__( - cls, - year: SupportsIndex, - month: SupportsIndex, - day: SupportsIndex, - hour: SupportsIndex, - minute: SupportsIndex, - second: SupportsIndex, - microsecond: SupportsIndex, - tzinfo: _TzInfo, + tzinfo: _TzInfo | None = None, *, fold: int = 0, - ) -> datetime[_TzInfo]: ... - + ) -> Self: ... @property def hour(self) -> int: ... @property @@ -325,64 +292,32 @@ class datetime(date, Generic[_TzInfoT]): @property def microsecond(self) -> int: ... @property - def tzinfo(self) -> _TzInfoT: ... + def tzinfo(self) -> _TzInfo | None: ... @property def fold(self) -> int: ... # On <3.12, the name of the first parameter in the pure-Python implementation # didn't match the name in the C implementation, # meaning it is only *safe* to pass it as a keyword argument on 3.12+ if sys.version_info >= (3, 12): - @overload # type: ignore[override] - @classmethod - def fromtimestamp(cls, timestamp: float, tz: None = None) -> datetime[None]: ... - @overload @classmethod - def fromtimestamp(cls, timestamp: float, tz: _TzInfo) -> datetime[_TzInfo]: ... - @overload - @classmethod - def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... - else: - @overload # type: ignore[override] - @classmethod - def fromtimestamp(cls, timestamp: float, /, tz: None = None) -> datetime[None]: ... - @overload - @classmethod - def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo) -> datetime[_TzInfo]: ... - @overload - @classmethod - def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None) -> datetime[_TzInfo] | datetime[None]: ... - - # fromisoformat returns Self, but we can't specialize "Self" - if sys.version_info >= (3, 15): - @classmethod - def fromisoformat(cls, string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] + def fromtimestamp(cls, timestamp: float, tz: _TzInfo | None = None) -> Self: ... else: @classmethod - def fromisoformat(cls, date_string: str, /) -> datetime[_TzInfo] | datetime[None]: ... # type: ignore[override] - - @classmethod - @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.UTC)") - def utcfromtimestamp(cls, t: float, /) -> datetime[None]: ... - - @overload - @classmethod - def now(cls, tz: None = None) -> datetime[None]: ... - @overload - @classmethod - def now(cls, tz: _TzInfo) -> datetime[_TzInfo]: ... + def fromtimestamp(cls, timestamp: float, /, tz: _TzInfo | None = None) -> Self: ... @classmethod - def today(cls) -> datetime[None]: ... # type: ignore[override] + @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .fromtimestamp(datetime.timezone.utc)") + def utcfromtimestamp(cls, t: float, /) -> Self: ... @classmethod - @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.UTC)") - def utcnow(cls) -> datetime[None]: ... - - @overload + def now(cls, tz: _TzInfo | None = None) -> Self: ... @classmethod - def combine(cls, date: _Date, time: _Time, tzinfo: None = None) -> datetime[None]: ... - @overload + @deprecated("Use timezone-aware objects to represent datetimes in UTC; e.g. by calling .now(datetime.timezone.utc)") + def utcnow(cls) -> Self: ... @classmethod - def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo) -> datetime[_TzInfo]: ... + def combine(cls, date: _Date, time: _Time, tzinfo: _TzInfo | None = ...) -> Self: ... + if sys.version_info >= (3, 15): + @classmethod + def fromisoformat(cls, string: str, /) -> Self: ... def timestamp(self) -> float: ... def utctimetuple(self) -> struct_time: ... @@ -405,7 +340,6 @@ class datetime(date, Generic[_TzInfoT]): fold: int = ..., ) -> Self: ... - @overload def replace( self, year: SupportsIndex = ..., @@ -415,67 +349,11 @@ class datetime(date, Generic[_TzInfoT]): minute: SupportsIndex = ..., second: SupportsIndex = ..., microsecond: SupportsIndex = ..., + tzinfo: _TzInfo | None = ..., *, fold: int = ..., ) -> Self: ... - @overload - def replace( - self, - year: SupportsIndex, - month: SupportsIndex, - day: SupportsIndex, - hour: SupportsIndex, - minute: SupportsIndex, - second: SupportsIndex, - microsecond: SupportsIndex, - tzinfo: _TzInfo, - *, - fold: int = ..., - ) -> datetime[_TzInfo]: ... - @overload - def replace( - self, - year: SupportsIndex = ..., - month: SupportsIndex = ..., - day: SupportsIndex = ..., - hour: SupportsIndex = ..., - minute: SupportsIndex = ..., - second: SupportsIndex = ..., - microsecond: SupportsIndex = ..., - *, - tzinfo: _TzInfo, - fold: int = ..., - ) -> datetime[_TzInfo]: ... - @overload - def replace( - self, - year: SupportsIndex, - month: SupportsIndex, - day: SupportsIndex, - hour: SupportsIndex, - minute: SupportsIndex, - second: SupportsIndex, - microsecond: SupportsIndex, - tzinfo: None, - *, - fold: int = ..., - ) -> datetime[None]: ... - @overload - def replace( - self, - year: SupportsIndex = ..., - month: SupportsIndex = ..., - day: SupportsIndex = ..., - hour: SupportsIndex = ..., - minute: SupportsIndex = ..., - second: SupportsIndex = ..., - microsecond: SupportsIndex = ..., - *, - tzinfo: None, - fold: int = ..., - ) -> datetime[None]: ... - - def astimezone(self, tz: _TzInfo | None = None) -> datetime[_TzInfo]: ... + def astimezone(self, tz: _TzInfo | None = None) -> Self: ... def isoformat(self, sep: str = "T", timespec: str = "auto") -> str: ... if sys.version_info >= (3, 15): @@ -488,56 +366,15 @@ class datetime(date, Generic[_TzInfoT]): def utcoffset(self) -> timedelta | None: ... def tzname(self) -> str | None: ... def dst(self) -> timedelta | None: ... - - @overload # type: ignore[override] - def __le__( # type: ignore[overload-overlap] - self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / - ) -> bool: ... # type: ignore[misc] - @overload - def __le__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] - @overload - def __le__(self: datetime[Any], value: datetime[Any], /) -> Never: ... - - @overload # type: ignore[override] - def __lt__( # type: ignore[overload-overlap] - self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / - ) -> bool: ... # type: ignore[misc] - @overload - def __lt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] - @overload - def __lt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... - - @overload # type: ignore[override] - def __ge__( # type: ignore[overload-overlap] - self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / - ) -> bool: ... # type: ignore[misc] - @overload - def __ge__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] - @overload - def __ge__(self: datetime[Any], value: datetime[Any], /) -> Never: ... - - @overload # type: ignore[override] - def __gt__( # type: ignore[overload-overlap] - self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / - ) -> bool: ... # type: ignore[misc] - @overload - def __gt__(self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], /) -> bool: ... # type: ignore[misc] - @overload - def __gt__(self: datetime[Any], value: datetime[Any], /) -> Never: ... - + def __le__(self, value: datetime, /) -> bool: ... # type: ignore[override] + def __lt__(self, value: datetime, /) -> bool: ... # type: ignore[override] + def __ge__(self, value: datetime, /) -> bool: ... # type: ignore[override] + def __gt__(self, value: datetime, /) -> bool: ... # type: ignore[override] def __eq__(self, value: object, /) -> bool: ... def __hash__(self) -> int: ... @overload # type: ignore[override] - def __sub__( # type: ignore[overload-overlap] - self: datetime[_TzInfo] | datetime[_TzInfo | None], value: datetime[_TzInfo] | datetime[_TzInfo | None], / - ) -> timedelta: ... - @overload - def __sub__( # type: ignore[overload-overlap] - self: datetime[None] | datetime[_TzInfo | None], value: datetime[None] | datetime[_TzInfo | None], / - ) -> timedelta: ... - @overload - def __sub__(self: datetime[Any], value: datetime[Any], /) -> Never: ... + def __sub__(self, value: Self, /) -> timedelta: ... @overload def __sub__(self, value: timedelta, /) -> Self: ...