From 467899e22367e787222daa10553ed308a2feb53c Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Thu, 7 Nov 2024 11:26:49 -0800 Subject: [PATCH 1/2] BZ2Compressor and BZ2Decompressor live in the _bz2 module --- stdlib/VERSIONS | 1 + stdlib/_bz2.pyi | 18 ++++++++++++++++++ stdlib/bz2.pyi | 19 ++----------------- 3 files changed, 21 insertions(+), 17 deletions(-) create mode 100644 stdlib/_bz2.pyi diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 7c9f3cfda837..c0c95f8df3e9 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -24,6 +24,7 @@ _asyncio: 3.0- _bisect: 3.0- _blake2: 3.6- _bootlocale: 3.4-3.9 +_bz2: 3.3- _codecs: 3.0- _collections_abc: 3.3- _compat_pickle: 3.1- diff --git a/stdlib/_bz2.pyi b/stdlib/_bz2.pyi new file mode 100644 index 000000000000..4ba26fe96be0 --- /dev/null +++ b/stdlib/_bz2.pyi @@ -0,0 +1,18 @@ +from _typeshed import ReadableBuffer +from typing import final + +@final +class BZ2Compressor: + def __init__(self, compresslevel: int = 9) -> None: ... + def compress(self, data: ReadableBuffer, /) -> bytes: ... + def flush(self) -> bytes: ... + +@final +class BZ2Decompressor: + def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ... + @property + def eof(self) -> bool: ... + @property + def needs_input(self) -> bool: ... + @property + def unused_data(self) -> bytes: ... diff --git a/stdlib/bz2.pyi b/stdlib/bz2.pyi index cd11baa1a0c1..ee5587031f2a 100644 --- a/stdlib/bz2.pyi +++ b/stdlib/bz2.pyi @@ -1,9 +1,10 @@ import _compression import sys +from _bz2 import BZ2Compressor as BZ2Compressor, BZ2Decompressor as BZ2Decompressor from _compression import BaseStream from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Iterable -from typing import IO, Any, Literal, Protocol, SupportsIndex, TextIO, final, overload +from typing import IO, Any, Literal, Protocol, SupportsIndex, TextIO, overload from typing_extensions import Self, TypeAlias __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "decompress"] @@ -128,19 +129,3 @@ class BZ2File(BaseStream, IO[bytes]): def seek(self, offset: int, whence: int = 0) -> int: ... def write(self, data: ReadableBuffer) -> int: ... def writelines(self, seq: Iterable[ReadableBuffer]) -> None: ... - -@final -class BZ2Compressor: - def __init__(self, compresslevel: int = 9) -> None: ... - def compress(self, data: ReadableBuffer, /) -> bytes: ... - def flush(self) -> bytes: ... - -@final -class BZ2Decompressor: - def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: ... - @property - def eof(self) -> bool: ... - @property - def needs_input(self) -> bool: ... - @property - def unused_data(self) -> bytes: ... From e7b5e790ac66d9f4757cb865b5be582793346204 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Thu, 7 Nov 2024 11:52:18 -0800 Subject: [PATCH 2/2] update allowlist --- stdlib/@tests/stubtest_allowlists/py310.txt | 2 +- stdlib/@tests/stubtest_allowlists/py311.txt | 2 +- stdlib/@tests/stubtest_allowlists/py38.txt | 2 +- stdlib/@tests/stubtest_allowlists/py39.txt | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index 8d0631cdd291..cff86548a029 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -3,7 +3,7 @@ _weakref.ProxyType.__reversed__ # Doesn't really exist asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them builtins.float.__setformat__ # Internal method for CPython test suite builtins.property.__set_name__ # Doesn't actually exist -bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set +_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set collections\.UserList\.index # ignoring pos-or-keyword parameter configparser.ParsingError.filename contextlib.AbstractAsyncContextManager.__class_getitem__ diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 5df7f76eb315..82e7ee7d6d7d 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -5,7 +5,7 @@ _collections_abc.Iterable.__class_getitem__ _collections_abc.MappingView.__class_getitem__ _csv.Reader _csv.Writer -bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set +_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set configparser.ParsingError.filename collections\.UserList\.index # ignoring pos-or-keyword parameter enum.Enum.__init__ diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index ace9fd78706d..e61f7e5ae2e7 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -14,7 +14,7 @@ asyncio.transports.WriteTransport.get_write_buffer_limits # Documented. Exists asyncio.WriteTransport.get_write_buffer_limits # Documented. Exists in subclasses, but not in WriteTransport itself builtins.float.__set_format__ # Internal method for CPython test suite builtins.input # Incorrect default value in text signature, fixed in 3.10 -bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set +_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491 diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 9c646178b383..0355043a9c6e 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -3,7 +3,7 @@ ast.ExtSlice.__new__ ast.Index.__new__ builtins.float.__setformat__ # Internal method for CPython test suite builtins.input # Incorrect default value in text signature, fixed in 3.10 -bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set +_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set collections.AsyncGenerator.asend # async at runtime, deliberately not in the stub, see #7491. Pos-only differences also. collections.AsyncGenerator.__anext__ # async at runtime, deliberately not in the stub, see #7491 collections.AsyncGenerator.aclose # async at runtime, deliberately not in the stub, see #7491