Skip to content

Deprecate _typeshed.Supports{Read,Write} #14149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stdlib/_csv.pyi
Original file line number Diff line number Diff line change
@@ -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]

Expand Down Expand Up @@ -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 = ",",
Expand Down
8 changes: 4 additions & 4 deletions stdlib/_curses.pyi
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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: ...

Expand Down Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions stdlib/_pickle.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
Expand All @@ -20,7 +20,7 @@ _ReducedType: TypeAlias = (

def dump(
obj: Any,
file: SupportsWrite[bytes],
file: Writer[bytes],
protocol: int | None = None,
*,
fix_imports: bool = True,
Expand Down Expand Up @@ -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: ...
Expand Down
6 changes: 3 additions & 3 deletions stdlib/_typeshed/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: ...

Expand All @@ -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: ...

Expand Down
5 changes: 2 additions & 3 deletions stdlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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: ...
Expand Down
10 changes: 5 additions & 5 deletions stdlib/argparse.pyi
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions stdlib/array.pyi
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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):
Expand All @@ -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: ...

Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/graph.pyi
Original file line number Diff line number Diff line change
@@ -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")

Expand All @@ -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: ...
10 changes: 3 additions & 7 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +69,7 @@ from typing_extensions import ( # noqa: Y023
TypeGuard,
TypeIs,
TypeVarTuple,
Writer,
deprecated,
)

Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions stdlib/configparser.pyi
Original file line number Diff line number Diff line change
@@ -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__ = (
Expand Down Expand Up @@ -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: ...
Expand Down
5 changes: 2 additions & 3 deletions stdlib/csv.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions stdlib/distutils/dist.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]

Expand Down Expand Up @@ -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: ...
Expand Down
22 changes: 8 additions & 14 deletions stdlib/email/generator.pyi
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -15,30 +14,25 @@ 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,
*,
policy: None = None,
) -> 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,
*,
Expand All @@ -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,
*,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions stdlib/email/iterators.pyi
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -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: ...
Loading