diff --git a/stdlib/_csv.pyi b/stdlib/_csv.pyi index ecea4878907c..351ccd6a1f46 100644 --- a/stdlib/_csv.pyi +++ b/stdlib/_csv.pyi @@ -1,9 +1,8 @@ import csv import sys -from _typeshed import SupportsWrite from collections.abc import Iterable from typing import Any, Final, Literal, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, Writer as _Writer __version__: Final[str] @@ -89,7 +88,7 @@ else: def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ... def writer( - csvfile: SupportsWrite[str], + csvfile: _Writer[str], dialect: _DialectLike = "excel", *, delimiter: str = ",", diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index f21a9ca60270..ee6b402450d9 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadOnlyBuffer, SupportsRead, SupportsWrite +from _typeshed import ReadOnlyBuffer from curses import _ncurses_version from typing import Any, final, overload -from typing_extensions import TypeAlias +from typing_extensions import Reader, TypeAlias, Writer # NOTE: This module is ordinarily only available on Unix, but the windows-curses # package makes it available on Windows as well with the same contents. @@ -297,7 +297,7 @@ def get_escdelay() -> int: ... def get_tabsize() -> int: ... def getmouse() -> tuple[int, int, int, int, int]: ... def getsyx() -> tuple[int, int]: ... -def getwin(file: SupportsRead[bytes], /) -> window: ... +def getwin(file: Reader[bytes], /) -> window: ... def halfdelay(tenths: int, /) -> None: ... def has_colors() -> bool: ... @@ -515,7 +515,7 @@ class window: # undocumented def overwrite( self, destwin: window, sminrow: int, smincol: int, dminrow: int, dmincol: int, dmaxrow: int, dmaxcol: int ) -> None: ... - def putwin(self, file: SupportsWrite[bytes], /) -> None: ... + def putwin(self, file: Writer[bytes], /) -> None: ... def redrawln(self, beg: int, num: int, /) -> None: ... def redrawwin(self) -> None: ... @overload diff --git a/stdlib/_pickle.pyi b/stdlib/_pickle.pyi index 8e8afb600efa..099d0d29816d 100644 --- a/stdlib/_pickle.pyi +++ b/stdlib/_pickle.pyi @@ -1,8 +1,8 @@ -from _typeshed import ReadableBuffer, SupportsWrite +from _typeshed import ReadableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from pickle import PickleBuffer as PickleBuffer from typing import Any, Protocol, type_check_only -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Writer class _ReadableFileobj(Protocol): def read(self, n: int, /) -> bytes: ... @@ -20,7 +20,7 @@ _ReducedType: TypeAlias = ( def dump( obj: Any, - file: SupportsWrite[bytes], + file: Writer[bytes], protocol: int | None = None, *, fix_imports: bool = True, @@ -62,11 +62,7 @@ class Pickler: reducer_override: Callable[[Any], Any] bin: bool # undocumented def __init__( - self, - file: SupportsWrite[bytes], - protocol: int | None = None, - fix_imports: bool = True, - buffer_callback: _BufferCallback = None, + self, file: Writer[bytes], protocol: int | None = None, fix_imports: bool = True, buffer_callback: _BufferCallback = None ) -> None: ... @property def memo(self) -> PicklerMemoProxy: ... diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index f322244016dd..0eaee4279d0d 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -22,7 +22,7 @@ from typing import ( final, overload, ) -from typing_extensions import Buffer, LiteralString, Self as _Self, TypeAlias +from typing_extensions import Buffer, LiteralString, Self as _Self, TypeAlias, deprecated _KT = TypeVar("_KT") _KT_co = TypeVar("_KT_co", covariant=True) @@ -253,7 +253,7 @@ FileDescriptor: TypeAlias = int # stable FileDescriptorLike: TypeAlias = int | HasFileno # stable FileDescriptorOrPath: TypeAlias = int | StrOrBytesPath -# stable +@deprecated("Use typing_extensions.Reader instead. Will be removed in December 2025 or later.") class SupportsRead(Protocol[_T_co]): def read(self, length: int = ..., /) -> _T_co: ... @@ -265,7 +265,7 @@ class SupportsReadline(Protocol[_T_co]): class SupportsNoArgReadline(Protocol[_T_co]): def readline(self) -> _T_co: ... -# stable +@deprecated("Use typing_extensions.Writer instead. Will be removed in December 2025 or later.") class SupportsWrite(Protocol[_T_contra]): def write(self, s: _T_contra, /) -> object: ... diff --git a/stdlib/abc.pyi b/stdlib/abc.pyi index fdca48ac7aaf..20acec96138d 100644 --- a/stdlib/abc.pyi +++ b/stdlib/abc.pyi @@ -1,9 +1,8 @@ import _typeshed import sys -from _typeshed import SupportsWrite from collections.abc import Callable from typing import Any, Literal, TypeVar -from typing_extensions import Concatenate, ParamSpec, deprecated +from typing_extensions import Concatenate, ParamSpec, Writer, deprecated _T = TypeVar("_T") _R_co = TypeVar("_R_co", covariant=True) @@ -24,7 +23,7 @@ class ABCMeta(type): def __instancecheck__(cls: ABCMeta, instance: Any) -> bool: ... def __subclasscheck__(cls: ABCMeta, subclass: type) -> bool: ... - def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = None) -> None: ... + def _dump_registry(cls: ABCMeta, file: Writer[str] | None = None) -> None: ... def register(cls: ABCMeta, subclass: type[_T]) -> type[_T]: ... def abstractmethod(funcobj: _FuncT) -> _FuncT: ... diff --git a/stdlib/argparse.pyi b/stdlib/argparse.pyi index 312093c0aa55..7c3717db8590 100644 --- a/stdlib/argparse.pyi +++ b/stdlib/argparse.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import SupportsWrite, sentinel +from _typeshed import sentinel from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern from typing import IO, Any, ClassVar, Final, Generic, NoReturn, Protocol, TypeVar, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, Writer, deprecated __all__ = [ "ArgumentParser", @@ -208,8 +208,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): help: str | None = None, metavar: str | None = None, ) -> _SubParsersAction[_ArgumentParserT]: ... - def print_usage(self, file: SupportsWrite[str] | None = None) -> None: ... - def print_help(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_usage(self, file: Writer[str] | None = None) -> None: ... + def print_help(self, file: Writer[str] | None = None) -> None: ... def format_usage(self) -> str: ... def format_help(self) -> str: ... @overload @@ -255,7 +255,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): def _get_value(self, action: Action, arg_string: str) -> Any: ... def _check_value(self, action: Action, value: Any) -> None: ... def _get_formatter(self) -> HelpFormatter: ... - def _print_message(self, message: str, file: SupportsWrite[str] | None = None) -> None: ... + def _print_message(self, message: str, file: Writer[str] | None = None) -> None: ... class HelpFormatter: # undocumented diff --git a/stdlib/array.pyi b/stdlib/array.pyi index bd96c9bc2d31..687fd8510908 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer from collections.abc import Iterable, MutableSequence from types import GenericAlias from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Reader, Self, TypeAlias, Writer _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] @@ -41,7 +41,7 @@ class array(MutableSequence[_T]): def count(self, v: _T, /) -> int: ... def extend(self, bb: Iterable[_T], /) -> None: ... def frombytes(self, buffer: ReadableBuffer, /) -> None: ... - def fromfile(self, f: SupportsRead[bytes], n: int, /) -> None: ... + def fromfile(self, f: Reader[bytes], n: int, /) -> None: ... def fromlist(self, list: list[_T], /) -> None: ... def fromunicode(self, ustr: str, /) -> None: ... if sys.version_info >= (3, 10): @@ -53,7 +53,7 @@ class array(MutableSequence[_T]): def pop(self, i: int = -1, /) -> _T: ... def remove(self, v: _T, /) -> None: ... def tobytes(self) -> bytes: ... - def tofile(self, f: SupportsWrite[bytes], /) -> None: ... + def tofile(self, f: Writer[bytes], /) -> None: ... def tolist(self) -> list[_T]: ... def tounicode(self) -> str: ... diff --git a/stdlib/asyncio/graph.pyi b/stdlib/asyncio/graph.pyi index cb2cf0174995..bb39b5d452d8 100644 --- a/stdlib/asyncio/graph.pyi +++ b/stdlib/asyncio/graph.pyi @@ -1,8 +1,8 @@ -from _typeshed import SupportsWrite from asyncio import Future from dataclasses import dataclass from types import FrameType from typing import Any, overload +from typing_extensions import Writer __all__ = ("capture_call_graph", "format_call_graph", "print_call_graph", "FrameCallGraphEntry", "FutureCallGraph") @@ -22,5 +22,5 @@ def capture_call_graph(future: None = None, /, *, depth: int = 1, limit: int | N def capture_call_graph(future: Future[Any], /, *, depth: int = 1, limit: int | None = None) -> FutureCallGraph | None: ... def format_call_graph(future: Future[Any] | None = None, /, *, depth: int = 1, limit: int | None = None) -> str: ... def print_call_graph( - future: Future[Any] | None = None, /, *, file: SupportsWrite[str] | None = None, depth: int = 1, limit: int | None = None + future: Future[Any] | None = None, /, *, file: Writer[str] | None = None, depth: int = 1, limit: int | None = None ) -> None: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 8de58f1a3d43..1ad1c6800a07 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -28,7 +28,6 @@ from _typeshed import ( SupportsRDivMod, SupportsRichComparison, SupportsRichComparisonT, - SupportsWrite, ) from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper @@ -70,6 +69,7 @@ from typing_extensions import ( # noqa: Y023 TypeGuard, TypeIs, TypeVarTuple, + Writer, deprecated, ) @@ -1768,15 +1768,11 @@ def open( ) -> IO[Any]: ... def ord(c: str | bytes | bytearray, /) -> int: ... -class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ... +class _SupportsWriteAndFlush(Writer[_T_contra], SupportsFlush, Protocol[_T_contra]): ... @overload def print( - *values: object, - sep: str | None = " ", - end: str | None = "\n", - file: SupportsWrite[str] | None = None, - flush: Literal[False] = False, + *values: object, sep: str | None = " ", end: str | None = "\n", file: Writer[str] | None = None, flush: Literal[False] = False ) -> None: ... @overload def print( diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index 15c564c02589..4d34bbac3f54 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import MaybeNone, StrOrBytesPath, SupportsWrite +from _typeshed import MaybeNone, StrOrBytesPath from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence from re import Pattern from typing import Any, ClassVar, Final, Literal, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Writer if sys.version_info >= (3, 14): __all__ = ( @@ -312,7 +312,7 @@ class RawConfigParser(_Parser): @overload def items(self, section: _SectionName, raw: bool = False, vars: _Section | None = None) -> list[tuple[str, str]]: ... def set(self, section: _SectionName, option: str, value: str | None = None) -> None: ... - def write(self, fp: SupportsWrite[str], space_around_delimiters: bool = True) -> None: ... + def write(self, fp: Writer[str], space_around_delimiters: bool = True) -> None: ... def remove_option(self, section: _SectionName, option: str) -> bool: ... def remove_section(self, section: _SectionName) -> bool: ... def optionxform(self, optionstr: str) -> str: ... diff --git a/stdlib/csv.pyi b/stdlib/csv.pyi index 2c8e7109cdfc..af1aded74d8f 100644 --- a/stdlib/csv.pyi +++ b/stdlib/csv.pyi @@ -24,11 +24,10 @@ if sys.version_info >= (3, 10): else: from _csv import _reader as Reader, _writer as Writer -from _typeshed import SupportsWrite 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 +from typing_extensions import Self, Writer as _Writer __all__ = [ "QUOTE_MINIMAL", @@ -128,7 +127,7 @@ class DictWriter(Generic[_T]): writer: Writer def __init__( self, - f: SupportsWrite[str], + f: _Writer[str], fieldnames: Collection[_T], restval: Any | None = "", extrasaction: Literal["raise", "ignore"] = "raise", diff --git a/stdlib/distutils/dist.pyi b/stdlib/distutils/dist.pyi index 412b94131b54..9d99573953b5 100644 --- a/stdlib/distutils/dist.pyi +++ b/stdlib/distutils/dist.pyi @@ -1,4 +1,4 @@ -from _typeshed import Incomplete, StrOrBytesPath, StrPath, SupportsWrite +from _typeshed import Incomplete, StrOrBytesPath, StrPath from collections.abc import Iterable, MutableMapping from distutils.cmd import Command from distutils.command.bdist import bdist @@ -23,7 +23,7 @@ from distutils.command.sdist import sdist from distutils.command.upload import upload from re import Pattern from typing import IO, ClassVar, Literal, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, Writer command_re: Pattern[str] @@ -51,7 +51,7 @@ class DistributionMetadata: obsoletes: list[str] | None def read_pkg_file(self, file: IO[str]) -> None: ... def write_pkg_info(self, base_dir: StrPath) -> None: ... - def write_pkg_file(self, file: SupportsWrite[str]) -> None: ... + def write_pkg_file(self, file: Writer[str]) -> None: ... def get_name(self) -> str: ... def get_version(self) -> str: ... def get_fullname(self) -> str: ... diff --git a/stdlib/email/generator.pyi b/stdlib/email/generator.pyi index d30e686299fa..d555e5091212 100644 --- a/stdlib/email/generator.pyi +++ b/stdlib/email/generator.pyi @@ -1,8 +1,7 @@ -from _typeshed import SupportsWrite from email.message import Message from email.policy import Policy from typing import Any, Generic, TypeVar, overload -from typing_extensions import Self +from typing_extensions import Self, Writer __all__ = ["Generator", "DecodedGenerator", "BytesGenerator"] @@ -15,7 +14,7 @@ class Generator(Generic[_MessageT]): @overload def __init__( self: Generator[Any], # The Policy of the message is used. - outfp: SupportsWrite[str], + outfp: Writer[str], mangle_from_: bool | None = None, maxheaderlen: int | None = None, *, @@ -23,22 +22,17 @@ class Generator(Generic[_MessageT]): ) -> None: ... @overload def __init__( - self, - outfp: SupportsWrite[str], - mangle_from_: bool | None = None, - maxheaderlen: int | None = None, - *, - policy: Policy[_MessageT], + self, outfp: Writer[str], mangle_from_: bool | None = None, maxheaderlen: int | None = None, *, policy: Policy[_MessageT] ) -> None: ... def write(self, s: str) -> None: ... def flatten(self, msg: _MessageT, unixfrom: bool = False, linesep: str | None = None) -> None: ... - def clone(self, fp: SupportsWrite[str]) -> Self: ... + def clone(self, fp: Writer[str]) -> Self: ... class BytesGenerator(Generator[_MessageT]): @overload def __init__( self: BytesGenerator[Any], # The Policy of the message is used. - outfp: SupportsWrite[bytes], + outfp: Writer[bytes], mangle_from_: bool | None = None, maxheaderlen: int | None = None, *, @@ -47,7 +41,7 @@ class BytesGenerator(Generator[_MessageT]): @overload def __init__( self, - outfp: SupportsWrite[bytes], + outfp: Writer[bytes], mangle_from_: bool | None = None, maxheaderlen: int | None = None, *, @@ -58,7 +52,7 @@ class DecodedGenerator(Generator[_MessageT]): @overload def __init__( self: DecodedGenerator[Any], # The Policy of the message is used. - outfp: SupportsWrite[str], + outfp: Writer[str], mangle_from_: bool | None = None, maxheaderlen: int | None = None, fmt: str | None = None, @@ -68,7 +62,7 @@ class DecodedGenerator(Generator[_MessageT]): @overload def __init__( self, - outfp: SupportsWrite[str], + outfp: Writer[str], mangle_from_: bool | None = None, maxheaderlen: int | None = None, fmt: str | None = None, diff --git a/stdlib/email/iterators.pyi b/stdlib/email/iterators.pyi index d964d6843833..d389d937cf0e 100644 --- a/stdlib/email/iterators.pyi +++ b/stdlib/email/iterators.pyi @@ -1,6 +1,6 @@ -from _typeshed import SupportsWrite from collections.abc import Iterator from email.message import Message +from typing_extensions import Writer __all__ = ["body_line_iterator", "typed_subpart_iterator", "walk"] @@ -9,4 +9,4 @@ def typed_subpart_iterator(msg: Message, maintype: str = "text", subtype: str | def walk(self: Message) -> Iterator[Message]: ... # We include the seemingly private function because it is documented in the stdlib documentation. -def _structure(msg: Message, fp: SupportsWrite[str] | None = None, level: int = 0, include_default: bool = False) -> None: ... +def _structure(msg: Message, fp: Writer[str] | None = None, level: int = 0, include_default: bool = False) -> None: ... diff --git a/stdlib/email/parser.pyi b/stdlib/email/parser.pyi index a4924a6cbd88..91f2a8bc52fd 100644 --- a/stdlib/email/parser.pyi +++ b/stdlib/email/parser.pyi @@ -1,4 +1,3 @@ -from _typeshed import SupportsRead from collections.abc import Callable from email._policybase import _MessageT from email.feedparser import BytesFeedParser as BytesFeedParser, FeedParser as FeedParser @@ -6,6 +5,7 @@ from email.message import Message from email.policy import Policy from io import _WrappedBuffer from typing import Generic, overload +from typing_extensions import Reader __all__ = ["Parser", "HeaderParser", "BytesParser", "BytesHeaderParser", "FeedParser", "BytesFeedParser"] @@ -16,11 +16,11 @@ class Parser(Generic[_MessageT]): def __init__(self, _class: None = None, *, policy: Policy[_MessageT]) -> None: ... @overload def __init__(self, _class: Callable[[], _MessageT] | None, *, policy: Policy[_MessageT] = ...) -> None: ... - def parse(self, fp: SupportsRead[str], headersonly: bool = False) -> _MessageT: ... + def parse(self, fp: Reader[str], headersonly: bool = False) -> _MessageT: ... def parsestr(self, text: str, headersonly: bool = False) -> _MessageT: ... class HeaderParser(Parser[_MessageT]): - def parse(self, fp: SupportsRead[str], headersonly: bool = True) -> _MessageT: ... + def parse(self, fp: Reader[str], headersonly: bool = True) -> _MessageT: ... def parsestr(self, text: str, headersonly: bool = True) -> _MessageT: ... class BytesParser(Generic[_MessageT]): diff --git a/stdlib/encodings/rot_13.pyi b/stdlib/encodings/rot_13.pyi index 8d71bc957594..7f33d22a959b 100644 --- a/stdlib/encodings/rot_13.pyi +++ b/stdlib/encodings/rot_13.pyi @@ -1,5 +1,5 @@ import codecs -from _typeshed import SupportsRead, SupportsWrite +from typing_extensions import Reader, Writer # This codec is string to string. @@ -20,4 +20,4 @@ def getregentry() -> codecs.CodecInfo: ... rot13_map: dict[int, int] -def rot13(infile: SupportsRead[str], outfile: SupportsWrite[str]) -> None: ... +def rot13(infile: Reader[str], outfile: Writer[str]) -> None: ... diff --git a/stdlib/ftplib.pyi b/stdlib/ftplib.pyi index 44bc2165fe0e..ec5ca71f6430 100644 --- a/stdlib/ftplib.pyi +++ b/stdlib/ftplib.pyi @@ -1,11 +1,11 @@ import sys -from _typeshed import SupportsRead, SupportsReadline +from _typeshed import SupportsReadline from collections.abc import Callable, Iterable, Iterator from socket import socket from ssl import SSLContext from types import TracebackType from typing import Any, Final, Literal, TextIO -from typing_extensions import Self +from typing_extensions import Reader, Self __all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"] @@ -83,7 +83,7 @@ class FTP: def storbinary( self, cmd: str, - fp: SupportsRead[bytes], + fp: Reader[bytes], blocksize: int = 8192, callback: Callable[[bytes], object] | None = None, rest: int | str | None = None, diff --git a/stdlib/http/client.pyi b/stdlib/http/client.pyi index 5c35dff28d43..7c719ab3cfa7 100644 --- a/stdlib/http/client.pyi +++ b/stdlib/http/client.pyi @@ -3,12 +3,12 @@ import io import ssl import sys import types -from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, WriteableBuffer +from _typeshed import MaybeNone, ReadableBuffer, SupportsReadline, WriteableBuffer from collections.abc import Callable, Iterable, Iterator, Mapping from email._policybase import _MessageT from socket import socket from typing import BinaryIO, Literal, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Reader, Self, TypeAlias __all__ = [ "HTTPResponse", @@ -32,7 +32,7 @@ __all__ = [ "HTTPSConnection", ] -_DataType: TypeAlias = SupportsRead[bytes] | Iterable[ReadableBuffer] | ReadableBuffer +_DataType: TypeAlias = Reader[bytes] | Iterable[ReadableBuffer] | ReadableBuffer _T = TypeVar("_T") _HeaderValue: TypeAlias = ReadableBuffer | str | int diff --git a/stdlib/http/server.pyi b/stdlib/http/server.pyi index 429bb65bb0ef..3fee4f83551a 100644 --- a/stdlib/http/server.pyi +++ b/stdlib/http/server.pyi @@ -4,11 +4,11 @@ import io import socketserver import sys from _ssl import _PasswordType -from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath from collections.abc import Callable, Iterable, Mapping, Sequence from ssl import Purpose, SSLContext from typing import Any, AnyStr, BinaryIO, ClassVar, Protocol, type_check_only -from typing_extensions import Self, deprecated +from typing_extensions import Reader, Self, Writer, deprecated if sys.version_info >= (3, 14): __all__ = [ @@ -115,7 +115,7 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def send_head(self) -> io.BytesIO | BinaryIO | None: ... # undocumented def list_directory(self, path: StrPath) -> io.BytesIO | None: ... # undocumented def translate_path(self, path: str) -> str: ... # undocumented - def copyfile(self, source: SupportsRead[AnyStr], outputfile: SupportsWrite[AnyStr]) -> None: ... # undocumented + def copyfile(self, source: Reader[AnyStr], outputfile: Writer[AnyStr]) -> None: ... # undocumented def guess_type(self, path: StrPath) -> str: ... # undocumented def executable(path: StrPath) -> bool: ... # undocumented diff --git a/stdlib/json/__init__.pyi b/stdlib/json/__init__.pyi index 63e9718ee151..08b62c60bd6a 100644 --- a/stdlib/json/__init__.pyi +++ b/stdlib/json/__init__.pyi @@ -1,6 +1,6 @@ -from _typeshed import SupportsRead, SupportsWrite from collections.abc import Callable from typing import Any +from typing_extensions import Reader, Writer from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder from .encoder import JSONEncoder as JSONEncoder @@ -23,7 +23,7 @@ def dumps( ) -> str: ... def dump( obj: Any, - fp: SupportsWrite[str], + fp: Writer[str], *, skipkeys: bool = False, ensure_ascii: bool = True, @@ -48,7 +48,7 @@ def loads( **kwds: Any, ) -> Any: ... def load( - fp: SupportsRead[str | bytes], + fp: Reader[str | bytes], *, cls: type[JSONDecoder] | None = None, object_hook: Callable[[dict[Any, Any]], Any] | None = None, diff --git a/stdlib/logging/__init__.pyi b/stdlib/logging/__init__.pyi index 24529bd48d6a..e71995677bcd 100644 --- a/stdlib/logging/__init__.pyi +++ b/stdlib/logging/__init__.pyi @@ -1,6 +1,6 @@ import sys import threading -from _typeshed import StrPath, SupportsWrite +from _typeshed import StrPath from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from io import TextIOWrapper from re import Pattern @@ -8,7 +8,7 @@ from string import Template from time import struct_time from types import FrameType, GenericAlias, TracebackType from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, Writer, deprecated __all__ = [ "BASIC_FORMAT", @@ -582,7 +582,7 @@ def basicConfig( datefmt: str | None = ..., style: _FormatStyle = ..., level: _Level | None = ..., - stream: SupportsWrite[str] | None = ..., + stream: Writer[str] | None = ..., handlers: Iterable[Handler] | None = ..., force: bool | None = ..., encoding: str | None = ..., @@ -595,7 +595,7 @@ def setLogRecordFactory(factory: Callable[..., LogRecord]) -> None: ... lastResort: Handler | None -_StreamT = TypeVar("_StreamT", bound=SupportsWrite[str]) +_StreamT = TypeVar("_StreamT", bound=Writer[str]) class StreamHandler(Handler, Generic[_StreamT]): stream: _StreamT # undocumented diff --git a/stdlib/mailbox.pyi b/stdlib/mailbox.pyi index ff605c0661fb..6a03a6cd80b7 100644 --- a/stdlib/mailbox.pyi +++ b/stdlib/mailbox.pyi @@ -1,13 +1,13 @@ import email.message import io import sys -from _typeshed import StrPath, SupportsNoArgReadline, SupportsRead +from _typeshed import StrPath, SupportsNoArgReadline from abc import ABCMeta, abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from email._policybase import _MessageT from types import GenericAlias, TracebackType from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Reader, Self, TypeAlias __all__ = [ "Mailbox", @@ -31,7 +31,7 @@ __all__ = [ _T = TypeVar("_T") -class _SupportsReadAndReadline(SupportsRead[bytes], SupportsNoArgReadline[bytes], Protocol): ... +class _SupportsReadAndReadline(Reader[bytes], SupportsNoArgReadline[bytes], Protocol): ... _MessageData: TypeAlias = email.message.Message | bytes | str | io.StringIO | _SupportsReadAndReadline diff --git a/stdlib/marshal.pyi b/stdlib/marshal.pyi index 46c421e4ce30..b04a14a1a77a 100644 --- a/stdlib/marshal.pyi +++ b/stdlib/marshal.pyi @@ -1,9 +1,9 @@ import builtins import sys import types -from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer from typing import Any, Final -from typing_extensions import TypeAlias +from typing_extensions import Reader, TypeAlias, Writer version: Final[int] @@ -29,21 +29,21 @@ _Marshallable: TypeAlias = ( ) if sys.version_info >= (3, 14): - def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 5, /, *, allow_code: bool = True) -> None: ... + def dump(value: _Marshallable, file: Writer[bytes], version: int = 5, /, *, allow_code: bool = True) -> None: ... def dumps(value: _Marshallable, version: int = 5, /, *, allow_code: bool = True) -> bytes: ... elif sys.version_info >= (3, 13): - def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 4, /, *, allow_code: bool = True) -> None: ... + def dump(value: _Marshallable, file: Writer[bytes], version: int = 4, /, *, allow_code: bool = True) -> None: ... def dumps(value: _Marshallable, version: int = 4, /, *, allow_code: bool = True) -> bytes: ... else: - def dump(value: _Marshallable, file: SupportsWrite[bytes], version: int = 4, /) -> None: ... + def dump(value: _Marshallable, file: Writer[bytes], version: int = 4, /) -> None: ... def dumps(value: _Marshallable, version: int = 4, /) -> bytes: ... if sys.version_info >= (3, 13): - def load(file: SupportsRead[bytes], /, *, allow_code: bool = True) -> Any: ... + def load(file: Reader[bytes], /, *, allow_code: bool = True) -> Any: ... def loads(bytes: ReadableBuffer, /, *, allow_code: bool = True) -> Any: ... else: - def load(file: SupportsRead[bytes], /) -> Any: ... + def load(file: Reader[bytes], /) -> Any: ... def loads(bytes: ReadableBuffer, /) -> Any: ... diff --git a/stdlib/multiprocessing/reduction.pyi b/stdlib/multiprocessing/reduction.pyi index 490ae195c20e..c132103c52df 100644 --- a/stdlib/multiprocessing/reduction.pyi +++ b/stdlib/multiprocessing/reduction.pyi @@ -1,7 +1,7 @@ import pickle import sys from _pickle import _ReducedType -from _typeshed import HasFileno, SupportsWrite, Unused +from _typeshed import HasFileno, Unused from abc import ABCMeta from builtins import type as Type # alias to avoid name clash from collections.abc import Callable @@ -9,6 +9,7 @@ from copyreg import _DispatchTableType from multiprocessing import connection from socket import socket from typing import Any, Final +from typing_extensions import Writer if sys.platform == "win32": __all__ = ["send_handle", "recv_handle", "ForkingPickler", "register", "dump", "DupHandle", "duplicate", "steal_handle"] @@ -19,7 +20,7 @@ HAVE_SEND_HANDLE: Final[bool] class ForkingPickler(pickle.Pickler): dispatch_table: _DispatchTableType - def __init__(self, file: SupportsWrite[bytes], protocol: int | None = ...) -> None: ... + def __init__(self, file: Writer[bytes], protocol: int | None = ...) -> None: ... @classmethod def register(cls, type: Type, reduce: Callable[[Any], _ReducedType]) -> None: ... @classmethod @@ -28,7 +29,7 @@ class ForkingPickler(pickle.Pickler): register = ForkingPickler.register -def dump(obj: Any, file: SupportsWrite[bytes], protocol: int | None = None) -> None: ... +def dump(obj: Any, file: Writer[bytes], protocol: int | None = None) -> None: ... if sys.platform == "win32": def duplicate( diff --git a/stdlib/optparse.pyi b/stdlib/optparse.pyi index 8b7fcd82e5a5..e1c21add697e 100644 --- a/stdlib/optparse.pyi +++ b/stdlib/optparse.pyi @@ -1,9 +1,9 @@ import builtins -from _typeshed import MaybeNone, SupportsWrite +from _typeshed import MaybeNone from abc import abstractmethod from collections.abc import Callable, Iterable, Mapping, Sequence from typing import Any, ClassVar, Final, Literal, NoReturn, overload -from typing_extensions import Self +from typing_extensions import Self, Writer __all__ = [ "Option", @@ -300,9 +300,9 @@ class OptionParser(OptionContainer): def get_usage(self) -> str: ... def get_version(self) -> str: ... def parse_args(self, args: list[str] | None = None, values: Values | None = None) -> tuple[Values, list[str]]: ... - def print_usage(self, file: SupportsWrite[str] | None = None) -> None: ... - def print_help(self, file: SupportsWrite[str] | None = None) -> None: ... - def print_version(self, file: SupportsWrite[str] | None = None) -> None: ... + def print_usage(self, file: Writer[str] | None = None) -> None: ... + def print_help(self, file: Writer[str] | None = None) -> None: ... + def print_version(self, file: Writer[str] | None = None) -> None: ... def set_default(self, dest: str, value: Any) -> None: ... # default value can be "any" type def set_defaults(self, **kwargs: Any) -> None: ... # default values can be "any" type def set_process_default_values(self, process: bool) -> None: ... diff --git a/stdlib/pickle.pyi b/stdlib/pickle.pyi index 2d80d61645e0..f4809bbdeddf 100644 --- a/stdlib/pickle.pyi +++ b/stdlib/pickle.pyi @@ -12,10 +12,10 @@ from _pickle import ( load as load, loads as loads, ) -from _typeshed import ReadableBuffer, SupportsWrite +from _typeshed import ReadableBuffer from collections.abc import Callable, Iterable, Mapping from typing import Any, ClassVar, SupportsBytes, SupportsIndex, final -from typing_extensions import Self +from typing_extensions import Self, Writer __all__ = [ "PickleBuffer", @@ -207,7 +207,7 @@ class _Pickler: reducer_override: Callable[[Any], Any] def __init__( self, - file: SupportsWrite[bytes], + file: Writer[bytes], protocol: int | None = None, *, fix_imports: bool = True, diff --git a/stdlib/pkgutil.pyi b/stdlib/pkgutil.pyi index e764d08e79f8..b36d3cc195f6 100644 --- a/stdlib/pkgutil.pyi +++ b/stdlib/pkgutil.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import StrOrBytesPath, SupportsRead +from _typeshed import StrOrBytesPath from _typeshed.importlib import LoaderProtocol, MetaPathFinderProtocol, PathEntryFinderProtocol from collections.abc import Callable, Iterable, Iterator from typing import IO, Any, NamedTuple, TypeVar -from typing_extensions import deprecated +from typing_extensions import Reader, deprecated __all__ = [ "get_importer", @@ -45,7 +45,7 @@ if sys.version_info < (3, 14): def get_importer(path_item: StrOrBytesPath) -> PathEntryFinderProtocol | None: ... def iter_importers(fullname: str = "") -> Iterator[MetaPathFinderProtocol | PathEntryFinderProtocol]: ... def iter_modules(path: Iterable[StrOrBytesPath] | None = None, prefix: str = "") -> Iterator[ModuleInfo]: ... -def read_code(stream: SupportsRead[bytes]) -> Any: ... # undocumented +def read_code(stream: Reader[bytes]) -> Any: ... # undocumented def walk_packages( path: Iterable[StrOrBytesPath] | None = None, prefix: str = "", onerror: Callable[[str], object] | None = None ) -> Iterator[ModuleInfo]: ... diff --git a/stdlib/pydoc.pyi b/stdlib/pydoc.pyi index f14b9d1bb699..c6ffe5baa1d6 100644 --- a/stdlib/pydoc.pyi +++ b/stdlib/pydoc.pyi @@ -1,12 +1,12 @@ import sys -from _typeshed import OptExcInfo, SupportsWrite, Unused +from _typeshed import OptExcInfo, Unused from abc import abstractmethod from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping from reprlib import Repr from types import MethodType, ModuleType, TracebackType from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeVar -from typing_extensions import TypeGuard, deprecated +from typing_extensions import TypeGuard, Writer, deprecated __all__ = ["help"] @@ -282,7 +282,7 @@ if sys.version_info >= (3, 11): thing: str | object, title: str = "Python Library Documentation: %s", forceload: bool = ..., - output: SupportsWrite[str] | None = None, + output: Writer[str] | None = None, is_cli: bool = False, ) -> None: ... @@ -291,7 +291,7 @@ else: thing: str | object, title: str = "Python Library Documentation: %s", forceload: bool = ..., - output: SupportsWrite[str] | None = None, + output: Writer[str] | None = None, ) -> None: ... def writedoc(thing: str | object, forceload: bool = ...) -> None: ... diff --git a/stdlib/pyexpat/__init__.pyi b/stdlib/pyexpat/__init__.pyi index 21e676052098..1f5031b335db 100644 --- a/stdlib/pyexpat/__init__.pyi +++ b/stdlib/pyexpat/__init__.pyi @@ -1,8 +1,8 @@ -from _typeshed import ReadableBuffer, SupportsRead +from _typeshed import ReadableBuffer from collections.abc import Callable from pyexpat import errors as errors, model as model from typing import Any, Final, final -from typing_extensions import CapsuleType, TypeAlias +from typing_extensions import CapsuleType, Reader, TypeAlias from xml.parsers.expat import ExpatError as ExpatError EXPAT_VERSION: Final[str] # undocumented @@ -20,7 +20,7 @@ _Model: TypeAlias = tuple[int, int, str | None, tuple[Any, ...]] @final class XMLParserType: def Parse(self, data: str | ReadableBuffer, isfinal: bool = False, /) -> int: ... - def ParseFile(self, file: SupportsRead[bytes], /) -> int: ... + def ParseFile(self, file: Reader[bytes], /) -> int: ... def SetBase(self, base: str, /) -> None: ... def GetBase(self) -> str | None: ... def GetInputContext(self) -> bytes | None: ... diff --git a/stdlib/quopri.pyi b/stdlib/quopri.pyi index b652e139bd0e..657cd57b208a 100644 --- a/stdlib/quopri.pyi +++ b/stdlib/quopri.pyi @@ -1,11 +1,12 @@ -from _typeshed import ReadableBuffer, SupportsNoArgReadline, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer, SupportsNoArgReadline from typing import Protocol +from typing_extensions import Reader, Writer __all__ = ["encode", "decode", "encodestring", "decodestring"] -class _Input(SupportsRead[bytes], SupportsNoArgReadline[bytes], Protocol): ... +class _Input(Reader[bytes], SupportsNoArgReadline[bytes], Protocol): ... -def encode(input: _Input, output: SupportsWrite[bytes], quotetabs: int, header: bool = False) -> None: ... +def encode(input: _Input, output: Writer[bytes], quotetabs: int, header: bool = False) -> None: ... def encodestring(s: ReadableBuffer, quotetabs: bool = False, header: bool = False) -> bytes: ... -def decode(input: _Input, output: SupportsWrite[bytes], header: bool = False) -> None: ... +def decode(input: _Input, output: Writer[bytes], header: bool = False) -> None: ... def decodestring(s: str | ReadableBuffer, header: bool = False) -> bytes: ... diff --git a/stdlib/shutil.pyi b/stdlib/shutil.pyi index c66d8fa128be..0b22236219cd 100644 --- a/stdlib/shutil.pyi +++ b/stdlib/shutil.pyi @@ -1,10 +1,10 @@ import os import sys -from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite +from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath from collections.abc import Callable, Iterable, Sequence from tarfile import _TarfileFilter from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload -from typing_extensions import TypeAlias, deprecated +from typing_extensions import Reader, TypeAlias, Writer, deprecated __all__ = [ "copyfileobj", @@ -53,7 +53,7 @@ else: class ReadError(OSError): ... class RegistryError(Exception): ... -def copyfileobj(fsrc: SupportsRead[AnyStr], fdst: SupportsWrite[AnyStr], length: int = 0) -> None: ... +def copyfileobj(fsrc: Reader[AnyStr], fdst: Writer[AnyStr], length: int = 0) -> None: ... def copyfile(src: StrOrBytesPath, dst: _StrOrBytesPathT, *, follow_symlinks: bool = True) -> _StrOrBytesPathT: ... def copymode(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ... def copystat(src: StrOrBytesPath, dst: StrOrBytesPath, *, follow_symlinks: bool = True) -> None: ... diff --git a/stdlib/tarfile.pyi b/stdlib/tarfile.pyi index 31094f87872d..1c172f963d5a 100644 --- a/stdlib/tarfile.pyi +++ b/stdlib/tarfile.pyi @@ -1,13 +1,13 @@ import bz2 import io import sys -from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, SupportsRead, WriteableBuffer +from _typeshed import ReadableBuffer, StrOrBytesPath, StrPath, WriteableBuffer from builtins import list as _list # aliases to avoid name clashes with fields named "type" or "list" from collections.abc import Callable, Iterable, Iterator, Mapping from gzip import _ReadableFileobj as _GzipReadableFileobj, _WritableFileobj as _GzipWritableFileobj from types import TracebackType from typing import IO, ClassVar, Literal, Protocol, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Reader, Self, TypeAlias, deprecated __all__ = [ "TarFile", @@ -570,7 +570,7 @@ class TarFile: *, filter: Callable[[TarInfo], TarInfo | None] | None = None, ) -> None: ... - def addfile(self, tarinfo: TarInfo, fileobj: SupportsRead[bytes] | None = None) -> None: ... + def addfile(self, tarinfo: TarInfo, fileobj: Reader[bytes] | None = None) -> None: ... def gettarinfo( self, name: StrOrBytesPath | None = None, arcname: str | None = None, fileobj: IO[bytes] | None = None ) -> TarInfo: ... diff --git a/stdlib/tomllib.pyi b/stdlib/tomllib.pyi index c160ffc38bfd..3238cecb5fc7 100644 --- a/stdlib/tomllib.pyi +++ b/stdlib/tomllib.pyi @@ -1,8 +1,7 @@ import sys -from _typeshed import SupportsRead from collections.abc import Callable from typing import Any, overload -from typing_extensions import deprecated +from typing_extensions import Reader, deprecated __all__ = ("loads", "load", "TOMLDecodeError") @@ -22,5 +21,5 @@ if sys.version_info >= (3, 14): else: class TOMLDecodeError(ValueError): ... -def load(fp: SupportsRead[bytes], /, *, parse_float: Callable[[str], Any] = ...) -> dict[str, Any]: ... +def load(fp: Reader[bytes], /, *, parse_float: Callable[[str], Any] = ...) -> dict[str, Any]: ... def loads(s: str, /, *, parse_float: Callable[[str], Any] = ...) -> dict[str, Any]: ... diff --git a/stdlib/traceback.pyi b/stdlib/traceback.pyi index 4553dbd08384..04e982c83d28 100644 --- a/stdlib/traceback.pyi +++ b/stdlib/traceback.pyi @@ -1,9 +1,9 @@ import sys -from _typeshed import SupportsWrite, Unused +from _typeshed import Unused from collections.abc import Generator, Iterable, Iterator, Mapping from types import FrameType, TracebackType from typing import Any, ClassVar, Literal, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, Writer, deprecated __all__ = [ "extract_stack", @@ -32,7 +32,7 @@ if sys.version_info >= (3, 14): _FrameSummaryTuple: TypeAlias = tuple[str, int, str, str | None] -def print_tb(tb: TracebackType | None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ... +def print_tb(tb: TracebackType | None, limit: int | None = None, file: Writer[str] | None = None) -> None: ... if sys.version_info >= (3, 10): @overload @@ -42,12 +42,12 @@ if sys.version_info >= (3, 10): value: BaseException | None = ..., tb: TracebackType | None = ..., limit: int | None = None, - file: SupportsWrite[str] | None = None, + file: Writer[str] | None = None, chain: bool = True, ) -> None: ... @overload def print_exception( - exc: BaseException, /, *, limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True + exc: BaseException, /, *, limit: int | None = None, file: Writer[str] | None = None, chain: bool = True ) -> None: ... @overload def format_exception( @@ -67,7 +67,7 @@ else: value: BaseException | None, tb: TracebackType | None, limit: int | None = None, - file: SupportsWrite[str] | None = None, + file: Writer[str] | None = None, chain: bool = True, ) -> None: ... def format_exception( @@ -78,13 +78,13 @@ else: chain: bool = True, ) -> list[str]: ... -def print_exc(limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ... -def print_last(limit: int | None = None, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ... -def print_stack(f: FrameType | None = None, limit: int | None = None, file: SupportsWrite[str] | None = None) -> None: ... +def print_exc(limit: int | None = None, file: Writer[str] | None = None, chain: bool = True) -> None: ... +def print_last(limit: int | None = None, file: Writer[str] | None = None, chain: bool = True) -> None: ... +def print_stack(f: FrameType | None = None, limit: int | None = None, file: Writer[str] | None = None) -> None: ... def extract_tb(tb: TracebackType | None, limit: int | None = None) -> StackSummary: ... def extract_stack(f: FrameType | None = None, limit: int | None = None) -> StackSummary: ... def format_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple]) -> list[str]: ... -def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file: SupportsWrite[str] | None = None) -> None: ... +def print_list(extracted_list: Iterable[FrameSummary | _FrameSummaryTuple], file: Writer[str] | None = None) -> None: ... if sys.version_info >= (3, 13): @overload @@ -242,7 +242,7 @@ class TracebackException: def format_exception_only(self) -> Generator[str, None, None]: ... if sys.version_info >= (3, 11): - def print(self, *, file: SupportsWrite[str] | None = None, chain: bool = True) -> None: ... + def print(self, *, file: Writer[str] | None = None, chain: bool = True) -> None: ... class FrameSummary: if sys.version_info >= (3, 11): diff --git a/stdlib/unittest/runner.pyi b/stdlib/unittest/runner.pyi index 783764464a53..9911b6876375 100644 --- a/stdlib/unittest/runner.pyi +++ b/stdlib/unittest/runner.pyi @@ -2,15 +2,15 @@ import sys import unittest.case import unittest.result import unittest.suite -from _typeshed import SupportsFlush, SupportsWrite +from _typeshed import SupportsFlush from collections.abc import Callable, Iterable from typing import Any, Generic, Protocol, TypeVar -from typing_extensions import Never, TypeAlias +from typing_extensions import Never, TypeAlias, Writer from warnings import _ActionKind _ResultClassType: TypeAlias = Callable[[_TextTestStream, bool, int], TextTestResult[Any]] -class _SupportsWriteAndFlush(SupportsWrite[str], SupportsFlush, Protocol): ... +class _SupportsWriteAndFlush(Writer[str], SupportsFlush, Protocol): ... # All methods used by unittest.runner.TextTestResult's stream class _TextTestStream(_SupportsWriteAndFlush, Protocol): @@ -28,7 +28,7 @@ class _WritelnDecorator: __getstate__: Never # Methods proxied from the wrapped stream object via __getattr__ def flush(self) -> object: ... - def write(self, s: str, /) -> object: ... + def write(self, s: str, /) -> int: ... _StreamT = TypeVar("_StreamT", bound=_TextTestStream, default=_WritelnDecorator) diff --git a/stdlib/urllib/request.pyi b/stdlib/urllib/request.pyi index d8fc5e0d8f48..dcba9fc9ba8f 100644 --- a/stdlib/urllib/request.pyi +++ b/stdlib/urllib/request.pyi @@ -1,13 +1,13 @@ import ssl import sys -from _typeshed import ReadableBuffer, StrOrBytesPath, SupportsRead +from _typeshed import ReadableBuffer, StrOrBytesPath from collections.abc import Callable, Iterable, Mapping, MutableMapping, Sequence from email.message import Message from http.client import HTTPConnection, HTTPMessage, HTTPResponse from http.cookiejar import CookieJar from re import Pattern from typing import IO, Any, ClassVar, NoReturn, Protocol, TypeVar, overload -from typing_extensions import TypeAlias, deprecated +from typing_extensions import Reader, TypeAlias, deprecated from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl @@ -50,7 +50,7 @@ if sys.version_info < (3, 14): _T = TypeVar("_T") _UrlopenRet: TypeAlias = Any -_DataType: TypeAlias = ReadableBuffer | SupportsRead[bytes] | Iterable[bytes] | None +_DataType: TypeAlias = ReadableBuffer | Reader[bytes] | Iterable[bytes] | None if sys.version_info >= (3, 13): def urlopen( diff --git a/stdlib/xml/dom/expatbuilder.pyi b/stdlib/xml/dom/expatbuilder.pyi index 228ad07e15ad..c44157f0b19c 100644 --- a/stdlib/xml/dom/expatbuilder.pyi +++ b/stdlib/xml/dom/expatbuilder.pyi @@ -1,6 +1,6 @@ -from _typeshed import ReadableBuffer, SupportsRead +from _typeshed import ReadableBuffer from typing import Any, NoReturn -from typing_extensions import TypeAlias +from typing_extensions import Reader, TypeAlias from xml.dom.minidom import Document, DocumentFragment, DOMImplementation, Element, Node, TypeInfo from xml.dom.xmlbuilder import DOMBuilderFilter, Options from xml.parsers.expat import XMLParserType @@ -34,7 +34,7 @@ class ExpatBuilder: def getParser(self) -> XMLParserType: ... def reset(self) -> None: ... def install(self, parser: XMLParserType) -> None: ... - def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> Document: ... + def parseFile(self, file: Reader[ReadableBuffer | str]) -> Document: ... def parseString(self, string: str | ReadableBuffer) -> Document: ... def start_doctype_decl_handler( self, doctypeName: str, systemId: str | None, publicId: str | None, has_internal_subset: bool @@ -88,7 +88,7 @@ class FragmentBuilder(ExpatBuilder): context: Node def __init__(self, context: Node, options: Options | None = None) -> None: ... def reset(self) -> None: ... - def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> DocumentFragment: ... # type: ignore[override] + def parseFile(self, file: Reader[ReadableBuffer | str]) -> DocumentFragment: ... # type: ignore[override] def parseString(self, string: ReadableBuffer | str) -> DocumentFragment: ... # type: ignore[override] def external_entity_ref_handler(self, context: str, base: str | None, systemId: str | None, publicId: str | None) -> int: ... @@ -106,7 +106,7 @@ class ParseEscape(Exception): ... class InternalSubsetExtractor(ExpatBuilder): subset: str | list[str] | None = None def getSubset(self) -> str: ... - def parseFile(self, file: SupportsRead[ReadableBuffer | str]) -> None: ... # type: ignore[override] + def parseFile(self, file: Reader[ReadableBuffer | str]) -> None: ... # type: ignore[override] def parseString(self, string: str | ReadableBuffer) -> None: ... # type: ignore[override] def start_doctype_decl_handler( # type: ignore[override] self, name: str, publicId: str | None, systemId: str | None, has_internal_subset: bool @@ -114,8 +114,8 @@ class InternalSubsetExtractor(ExpatBuilder): def end_doctype_decl_handler(self) -> NoReturn: ... def start_element_handler(self, name: str, attrs: list[str]) -> NoReturn: ... -def parse(file: str | SupportsRead[ReadableBuffer | str], namespaces: bool = True) -> Document: ... +def parse(file: str | Reader[ReadableBuffer | str], namespaces: bool = True) -> Document: ... def parseString(string: str | ReadableBuffer, namespaces: bool = True) -> Document: ... -def parseFragment(file: str | SupportsRead[ReadableBuffer | str], context: Node, namespaces: bool = True) -> DocumentFragment: ... +def parseFragment(file: str | Reader[ReadableBuffer | str], context: Node, namespaces: bool = True) -> DocumentFragment: ... def parseFragmentString(string: str | ReadableBuffer, context: Node, namespaces: bool = True) -> DocumentFragment: ... def makeBuilder(options: Options) -> ExpatBuilderNS | ExpatBuilder: ... diff --git a/stdlib/xml/dom/minidom.pyi b/stdlib/xml/dom/minidom.pyi index ab2ef87e38a8..14531aa3c54f 100644 --- a/stdlib/xml/dom/minidom.pyi +++ b/stdlib/xml/dom/minidom.pyi @@ -1,10 +1,10 @@ import xml.dom from _collections_abc import dict_keys, dict_values -from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite +from _typeshed import Incomplete, ReadableBuffer from collections.abc import Iterable, Sequence from types import TracebackType from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Reader, Self, TypeAlias, Writer from xml.dom.minicompat import EmptyNodeList, NodeList from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS from xml.sax.xmlreader import XMLReader @@ -46,9 +46,7 @@ class _DOMErrorHandler(Protocol): class _UserDataHandler(Protocol): def handle(self, operation: int, key: str, data: Any, src: Node, dst: Node) -> None: ... -def parse( - file: str | SupportsRead[ReadableBuffer | str], parser: XMLReader | None = None, bufsize: int | None = None -) -> Document: ... +def parse(file: str | Reader[ReadableBuffer | str], parser: XMLReader | None = None, bufsize: int | None = None) -> Document: ... def parseString(string: str | ReadableBuffer, parser: XMLReader | None = None) -> Document: ... @overload def getDOMImplementation(features: None = None) -> DOMImplementation: ... @@ -311,7 +309,7 @@ class Element(Node): def hasAttributeNS(self, namespaceURI: str | None, localName: str) -> bool: ... def getElementsByTagName(self, name: str) -> NodeList[Element]: ... def getElementsByTagNameNS(self, namespaceURI: str | None, localName: str) -> NodeList[Element]: ... - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... def hasAttributes(self) -> bool: ... def setIdAttribute(self, name: str) -> None: ... def setIdAttributeNS(self, namespaceURI: str | None, localName: str) -> None: ... @@ -368,7 +366,7 @@ class ProcessingInstruction(Childless, Node): data: str def __init__(self, target: str, data: str) -> None: ... - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class CharacterData(Childless, Node): nodeValue: str @@ -416,7 +414,7 @@ class Text(CharacterData): data: str def splitText(self, offset: int) -> Self: ... - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... def replaceWholeText(self, content: str) -> Self | None: ... @property def isWhitespaceInElementContent(self) -> bool: ... @@ -443,7 +441,7 @@ class Comment(CharacterData): @property def localName(self) -> None: ... def __init__(self, data: str) -> None: ... - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class CDATASection(Text): nodeType: ClassVar[Literal[4]] # type: ignore[assignment] @@ -455,7 +453,7 @@ class CDATASection(Text): nextSibling: _DocumentFragmentChildren | _ElementChildren | None previousSibling: _DocumentFragmentChildren | _ElementChildren | None - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class ReadOnlySequentialNamedNodeMap(Generic[_N]): def __init__(self, seq: Sequence[_N] = ()) -> None: ... @@ -502,7 +500,7 @@ class DocumentType(Identified, Childless, Node): def __init__(self, qualifiedName: str | None) -> None: ... def cloneNode(self, deep: bool) -> DocumentType | None: ... - def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... + def writexml(self, writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class Entity(Identified, Node): nodeType: ClassVar[Literal[6]] @@ -626,7 +624,7 @@ class Document(Node, DocumentLS): def importNode(self, node: _ImportableNodeVar, deep: bool) -> _ImportableNodeVar: ... def writexml( self, - writer: SupportsWrite[str], + writer: Writer[str], indent: str = "", addindent: str = "", newl: str = "", diff --git a/stdlib/xml/dom/xmlbuilder.pyi b/stdlib/xml/dom/xmlbuilder.pyi index 6fb18bbc4eda..711582e6780e 100644 --- a/stdlib/xml/dom/xmlbuilder.pyi +++ b/stdlib/xml/dom/xmlbuilder.pyi @@ -1,5 +1,5 @@ -from _typeshed import SupportsRead from typing import Any, Literal, NoReturn +from typing_extensions import Reader from xml.dom.minidom import Document, Node, _DOMErrorHandler __all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"] @@ -47,8 +47,8 @@ class DOMEntityResolver: def resolveEntity(self, publicId: str | None, systemId: str) -> DOMInputSource: ... class DOMInputSource: - byteStream: SupportsRead[bytes] | None - characterStream: SupportsRead[str] | None + byteStream: Reader[bytes] | None + characterStream: Reader[str] | None stringData: str | None encoding: str | None publicId: str | None diff --git a/stdlib/xml/etree/ElementTree.pyi b/stdlib/xml/etree/ElementTree.pyi index 4c55a1a7452e..6ee1b12dd426 100644 --- a/stdlib/xml/etree/ElementTree.pyi +++ b/stdlib/xml/etree/ElementTree.pyi @@ -1,9 +1,9 @@ import sys from _collections_abc import dict_keys -from _typeshed import FileDescriptorOrPath, ReadableBuffer, SupportsRead, SupportsWrite +from _typeshed import FileDescriptorOrPath, ReadableBuffer from collections.abc import Callable, Generator, ItemsView, Iterable, Iterator, Mapping, Sequence from typing import Any, Final, Generic, Literal, Protocol, SupportsIndex, TypeVar, overload, type_check_only -from typing_extensions import TypeAlias, TypeGuard, deprecated +from typing_extensions import Reader, TypeAlias, TypeGuard, Writer, deprecated from xml.parsers.expat import XMLParserType __all__ = [ @@ -36,9 +36,9 @@ __all__ = [ ] _T = TypeVar("_T") -_FileRead: TypeAlias = FileDescriptorOrPath | SupportsRead[bytes] | SupportsRead[str] -_FileWriteC14N: TypeAlias = FileDescriptorOrPath | SupportsWrite[bytes] -_FileWrite: TypeAlias = _FileWriteC14N | SupportsWrite[str] +_FileRead: TypeAlias = FileDescriptorOrPath | Reader[bytes] | Reader[str] +_FileWriteC14N: TypeAlias = FileDescriptorOrPath | Writer[bytes] +_FileWrite: TypeAlias = _FileWriteC14N | Writer[str] VERSION: Final[str] @@ -66,7 +66,7 @@ def canonicalize( def canonicalize( xml_data: str | ReadableBuffer | None = None, *, - out: SupportsWrite[str], + out: Writer[str], from_file: _FileRead | None = None, with_comments: bool = False, strip_text: bool = False, diff --git a/stdlib/xml/sax/__init__.pyi b/stdlib/xml/sax/__init__.pyi index ebe92d28c74d..de3a66406ec8 100644 --- a/stdlib/xml/sax/__init__.pyi +++ b/stdlib/xml/sax/__init__.pyi @@ -1,8 +1,8 @@ import sys -from _typeshed import ReadableBuffer, StrPath, SupportsRead, _T_co +from _typeshed import ReadableBuffer, StrPath, _T_co from collections.abc import Iterable from typing import Protocol -from typing_extensions import TypeAlias +from typing_extensions import Reader, TypeAlias from xml.sax._exceptions import ( SAXException as SAXException, SAXNotRecognizedException as SAXNotRecognizedException, @@ -13,7 +13,7 @@ from xml.sax._exceptions import ( from xml.sax.handler import ContentHandler as ContentHandler, ErrorHandler as ErrorHandler from xml.sax.xmlreader import InputSource as InputSource, XMLReader -class _SupportsReadClose(SupportsRead[_T_co], Protocol[_T_co]): +class _SupportsReadClose(Reader[_T_co], Protocol[_T_co]): def close(self) -> None: ... _Source: TypeAlias = StrPath | _SupportsReadClose[bytes] | _SupportsReadClose[str] diff --git a/stdlib/xml/sax/saxutils.pyi b/stdlib/xml/sax/saxutils.pyi index a29588faae2a..4c7bbbe015e4 100644 --- a/stdlib/xml/sax/saxutils.pyi +++ b/stdlib/xml/sax/saxutils.pyi @@ -1,8 +1,8 @@ -from _typeshed import SupportsWrite from codecs import StreamReaderWriter, StreamWriter from collections.abc import Mapping from io import RawIOBase, TextIOBase from typing import Literal, NoReturn +from typing_extensions import Writer from xml.sax import _Source, handler, xmlreader def escape(data: str, entities: Mapping[str, str] = {}) -> str: ... @@ -12,7 +12,7 @@ def quoteattr(data: str, entities: Mapping[str, str] = {}) -> str: ... class XMLGenerator(handler.ContentHandler): def __init__( self, - out: TextIOBase | RawIOBase | StreamWriter | StreamReaderWriter | SupportsWrite[bytes] | None = None, + out: TextIOBase | RawIOBase | StreamWriter | StreamReaderWriter | Writer[bytes] | None = None, encoding: str = "iso-8859-1", short_empty_elements: bool = False, ) -> None: ... diff --git a/stdlib/xmlrpc/client.pyi b/stdlib/xmlrpc/client.pyi index 6cc4361f4a09..0fe054b8de2f 100644 --- a/stdlib/xmlrpc/client.pyi +++ b/stdlib/xmlrpc/client.pyi @@ -1,13 +1,13 @@ import gzip import http.client import time -from _typeshed import ReadableBuffer, SizedBuffer, SupportsRead, SupportsWrite +from _typeshed import ReadableBuffer, SizedBuffer from collections.abc import Callable, Iterable, Mapping from datetime import datetime from io import BytesIO from types import TracebackType from typing import Any, ClassVar, Final, Literal, Protocol, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Reader, Self, TypeAlias, Writer class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... @@ -85,7 +85,7 @@ class DateTime: def make_comparable(self, other: _DateTimeComparable) -> tuple[str, str]: ... # undocumented def timetuple(self) -> time.struct_time: ... # undocumented def decode(self, data: Any) -> None: ... - def encode(self, out: SupportsWrite[str]) -> None: ... + def encode(self, out: Writer[str]) -> None: ... def _datetime(data: Any) -> DateTime: ... # undocumented def _datetime_type(data: str) -> datetime: ... # undocumented @@ -94,7 +94,7 @@ class Binary: data: bytes def __init__(self, data: bytes | bytearray | None = None) -> None: ... def decode(self, data: ReadableBuffer) -> None: ... - def encode(self, out: SupportsWrite[str]) -> None: ... + def encode(self, out: Writer[str]) -> None: ... def __eq__(self, other: object) -> bool: ... __hash__: ClassVar[None] # type: ignore[assignment] @@ -208,7 +208,7 @@ def gzip_decode(data: ReadableBuffer, max_decode: int = 20971520) -> bytes: ... class GzipDecodedResponse(gzip.GzipFile): # undocumented io: BytesIO - def __init__(self, response: SupportsRead[ReadableBuffer]) -> None: ... + def __init__(self, response: Reader[ReadableBuffer]) -> None: ... class _Method: # undocumented __send: Callable[[str, tuple[_Marshallable, ...]], _Marshallable]