From 631c9924cf31bf33059868b337289635e1d6b974 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Sun, 17 Nov 2024 23:40:30 -0800 Subject: [PATCH] improve unexposed zlib types (#13032) Co-authored-by: Alex Waygood --- stdlib/zlib.pyi | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/stdlib/zlib.pyi b/stdlib/zlib.pyi index 2f6c40656..7cafb44b3 100644 --- a/stdlib/zlib.pyi +++ b/stdlib/zlib.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import ReadableBuffer -from typing import Final +from typing import Any, Final, final, type_check_only +from typing_extensions import Self DEFLATED: Final = 8 DEF_MEM_LEVEL: int # can change @@ -27,17 +28,30 @@ Z_TREES: Final = 6 class error(Exception): ... +# This class is not exposed at runtime. It calls itself zlib.Compress. +@final +@type_check_only class _Compress: - def compress(self, data: ReadableBuffer) -> bytes: ... - def flush(self, mode: int = ...) -> bytes: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, memo: Any, /) -> Self: ... + def compress(self, data: ReadableBuffer, /) -> bytes: ... + def flush(self, mode: int = 4, /) -> bytes: ... def copy(self) -> _Compress: ... +# This class is not exposed at runtime. It calls itself zlib.Decompress. +@final +@type_check_only class _Decompress: - unused_data: bytes - unconsumed_tail: bytes - eof: bool - def decompress(self, data: ReadableBuffer, max_length: int = ...) -> bytes: ... - def flush(self, length: int = ...) -> bytes: ... + @property + def unused_data(self) -> bytes: ... + @property + def unconsumed_tail(self) -> bytes: ... + @property + def eof(self) -> bool: ... + def __copy__(self) -> Self: ... + def __deepcopy__(self, memo: Any, /) -> Self: ... + def decompress(self, data: ReadableBuffer, /, max_length: int = 0) -> bytes: ... + def flush(self, length: int = 16384, /) -> bytes: ... def copy(self) -> _Decompress: ... def adler32(data: ReadableBuffer, value: int = 1, /) -> int: ...