Add @type_check_only to stub-only private classes in stdlib (#14512)

This commit is contained in:
Brian Schubert
2025-08-03 04:13:16 -04:00
committed by GitHub
parent dde70aeecd
commit 622df68c1c
61 changed files with 188 additions and 51 deletions
+9 -1
View File
@@ -5,7 +5,7 @@ from collections.abc import Callable, Iterable, Iterator
from io import TextIOWrapper
from os import PathLike
from types import TracebackType
from typing import IO, Final, Literal, Protocol, overload
from typing import IO, Final, Literal, Protocol, overload, type_check_only
from typing_extensions import Self, TypeAlias
__all__ = [
@@ -41,6 +41,7 @@ error = BadZipfile
class LargeZipFile(Exception): ...
@type_check_only
class _ZipStream(Protocol):
def read(self, n: int, /) -> bytes: ...
# The following methods are optional:
@@ -49,11 +50,13 @@ class _ZipStream(Protocol):
# def seek(self, n: int, /) -> object: ...
# Stream shape as required by _EndRecData() and _EndRecData64().
@type_check_only
class _SupportsReadSeekTell(Protocol):
def read(self, n: int = ..., /) -> bytes: ...
def seek(self, cookie: int, whence: int, /) -> object: ...
def tell(self) -> int: ...
@type_check_only
class _ClosableZipStream(_ZipStream, Protocol):
def close(self) -> object: ...
@@ -93,18 +96,23 @@ class ZipExtFile(io.BufferedIOBase):
def read1(self, n: int | None) -> bytes: ... # type: ignore[override]
def seek(self, offset: int, whence: int = 0) -> int: ...
@type_check_only
class _Writer(Protocol):
def write(self, s: str, /) -> object: ...
@type_check_only
class _ZipReadable(Protocol):
def seek(self, offset: int, whence: int = 0, /) -> int: ...
def read(self, n: int = -1, /) -> bytes: ...
@type_check_only
class _ZipTellable(Protocol):
def tell(self) -> int: ...
@type_check_only
class _ZipReadableTellable(_ZipReadable, _ZipTellable, Protocol): ...
@type_check_only
class _ZipWritable(Protocol):
def flush(self) -> None: ...
def close(self) -> None: ...