From 13143f81eb124945f7c019326bdfebf684963a24 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sat, 27 Jan 2018 18:32:25 +0000 Subject: [PATCH 1/9] Add type stub for the lzma module --- stdlib/3.3/lzma.pyi | 105 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 stdlib/3.3/lzma.pyi diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi new file mode 100644 index 000000000000..a945f3bd1090 --- /dev/null +++ b/stdlib/3.3/lzma.pyi @@ -0,0 +1,105 @@ +import io +import sys +from typing import Any, Dict, BinaryIO, IO, List, Optional, Union + +if sys.version_info >= (3, 6): + from os import PathLike + _PathOrFile = Union[str, bytes, IO[Any], PathLike[Any]] +elif sys.version_info >= (3, 3): + _PathOrFile = Union[str, bytes, IO[Any]] +else: + _PathOrFile = str + +_FilterChain = List[Dict[str, Any]] + +FORMAT_AUTO: int +FORMAT_XZ: int +FORMAT_ALONE: int +FORMAT_RAW: int +CHECK_NONE: int +CHECK_CRC32: int +CHECK_CRC64: int +CHECK_SHA256: int +CHECK_ID_MAX: int +CHECK_UNKNOWN: int +FILTER_LZMA1: int +FILTER_LZMA2: int +FILTER_DELTA: int +FILTER_X86: int +FILTER_IA64: int +FILTER_ARM: int +FILTER_ARMTHUMB: int +FILTER_SPARC: int +FILTER_POWERPC: int +MF_HC3: int +MF_HC4: int +MF_BT2: int +MF_BT3: int +MF_BT4: int +MODE_FAST: int +MODE_NORMAL: int +PRESET_DEFAULT: int +PRESET_EXTREME: int + +# from _lzma.c +class LZMADecompressor(object): + def __init__(self, format: Optional[int] = ..., memlimit: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> None: ... + def decompress(self, data: bytes, max_length: int = ...) -> bytes: ... + @property + def check(self) -> int: ... + @property + def eof(self) -> bool: ... + @property + def unused_data(self) -> bytes: ... + if sys.version_info >= (3, 5): + @property + def needs_input(self) -> bool: ... + +# from _lzma.c +class LZMACompressor(object): + def __init__(self, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ...) -> None: ... + def compress(self, data: bytes) -> bytes: ... + def flush(self) -> bytes: ... + + +class LZMAFile(io.BufferedIOBase): + def __init__(self, + filename: _PathOrFile = ..., + mode: str = ..., + *, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ...) -> None: ... + def close(self) -> None: ... + @property + def closed(self) -> bool: ... + def fileno(self) -> int: ... + def seekable(self) -> bool: ... + def readable(self) -> bool: ... + def writable(self) -> bool: ... + def peek(self, size: int = ...) -> bytes: ... + def read(self, size: int = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + def readline(self, size: int = ...) -> bytes: ... + def write(self, data: bytes) -> int: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + + +def open(filename: _PathOrFile = ..., + mode: str = ..., + *, + format: Optional[int] = ..., + check: int = ..., + preset: Optional[int] = ..., + filters: Optional[_FilterChain] = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ...) -> IO[Any]: ... +def compress(data: bytes, format: int = ..., check: int = ..., preset: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... +def decompress(data: bytes, format: int = ..., memlimit: Optional[int]= ..., filters: Optional[_FilterChain] = ...) -> bytes: ... From 5e1726c013c8b1a29b142ea7a611c01ab83340b7 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Sat, 27 Jan 2018 18:52:40 +0000 Subject: [PATCH 2/9] Claim to extend BinaryIO to resolve test failures This doesn't record the true hierarchy of the type, though avoids errors from mypy that 'Argument 1 of "read" incompatible with supertype "BufferedIOBase"'. --- stdlib/3.3/lzma.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index a945f3bd1090..86bcda09a25a 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -66,7 +66,7 @@ class LZMACompressor(object): def flush(self) -> bytes: ... -class LZMAFile(io.BufferedIOBase): +class LZMAFile(BinaryIO): def __init__(self, filename: _PathOrFile = ..., mode: str = ..., From 0339a8f8e9c7d50070eeb9ea43894b9a83a3dc87 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 29 Jan 2018 12:32:00 +0000 Subject: [PATCH 3/9] Whitespace --- stdlib/3.3/lzma.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index 86bcda09a25a..3426272520ef 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -102,4 +102,4 @@ def open(filename: _PathOrFile = ..., errors: Optional[str] = ..., newline: Optional[str] = ...) -> IO[Any]: ... def compress(data: bytes, format: int = ..., check: int = ..., preset: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... -def decompress(data: bytes, format: int = ..., memlimit: Optional[int]= ..., filters: Optional[_FilterChain] = ...) -> bytes: ... +def decompress(data: bytes, format: int = ..., memlimit: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... From a824afe89cf1d46586df32af9663c9a497726a7e Mon Sep 17 00:00:00 2001 From: Peter Law Date: Mon, 29 Jan 2018 12:38:13 +0000 Subject: [PATCH 4/9] Filter chains can actually be any mapping --- stdlib/3.3/lzma.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index 3426272520ef..c73ab96dc938 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -1,6 +1,6 @@ import io import sys -from typing import Any, Dict, BinaryIO, IO, List, Optional, Union +from typing import Any, BinaryIO, IO, List, Mapping, Optional, Union if sys.version_info >= (3, 6): from os import PathLike @@ -10,7 +10,7 @@ elif sys.version_info >= (3, 3): else: _PathOrFile = str -_FilterChain = List[Dict[str, Any]] +_FilterChain = List[Mapping[str, Any]] FORMAT_AUTO: int FORMAT_XZ: int From ff7fe24954ccac94852449bc90c988140e3500b1 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 1 Feb 2018 01:29:44 +0000 Subject: [PATCH 5/9] Fix defaults for filename --- stdlib/3.3/lzma.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index c73ab96dc938..b5d9ab2ea823 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -68,7 +68,7 @@ class LZMACompressor(object): class LZMAFile(BinaryIO): def __init__(self, - filename: _PathOrFile = ..., + filename: Optional[_PathOrFile] = ..., mode: str = ..., *, format: Optional[int] = ..., @@ -91,7 +91,7 @@ class LZMAFile(BinaryIO): def tell(self) -> int: ... -def open(filename: _PathOrFile = ..., +def open(filename: _PathOrFile, mode: str = ..., *, format: Optional[int] = ..., From 2ae4a6d022c6aebc6a87b9052f7ee4f0d98380b1 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 1 Feb 2018 01:30:19 +0000 Subject: [PATCH 6/9] Remove redundant if and else lzma is only in 3.3 and later, so the elif was actually already an else. --- stdlib/3.3/lzma.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index b5d9ab2ea823..22705e177dcd 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -5,10 +5,8 @@ from typing import Any, BinaryIO, IO, List, Mapping, Optional, Union if sys.version_info >= (3, 6): from os import PathLike _PathOrFile = Union[str, bytes, IO[Any], PathLike[Any]] -elif sys.version_info >= (3, 3): - _PathOrFile = Union[str, bytes, IO[Any]] else: - _PathOrFile = str + _PathOrFile = Union[str, bytes, IO[Any]] _FilterChain = List[Mapping[str, Any]] From 444d0ccb1dee0129fe18da07ea6dd5e8f0e1410b Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 1 Feb 2018 01:36:00 +0000 Subject: [PATCH 7/9] Add overlooked exception class --- stdlib/3.3/lzma.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index 22705e177dcd..5bafdc2780c5 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -64,6 +64,9 @@ class LZMACompressor(object): def flush(self) -> bytes: ... +class LZMAError(Exception): ... + + class LZMAFile(BinaryIO): def __init__(self, filename: Optional[_PathOrFile] = ..., From cb0e8acbae76aefef8a9dc792563c82ba5463410 Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 1 Feb 2018 01:39:57 +0000 Subject: [PATCH 8/9] Add overlooked function --- stdlib/3.3/lzma.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index 5bafdc2780c5..9ca91e1c10a1 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -104,3 +104,4 @@ def open(filename: _PathOrFile, newline: Optional[str] = ...) -> IO[Any]: ... def compress(data: bytes, format: int = ..., check: int = ..., preset: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... def decompress(data: bytes, format: int = ..., memlimit: Optional[int] = ..., filters: Optional[_FilterChain] = ...) -> bytes: ... +def is_check_supported(check: int) -> bool: ... From fc4eb126b00192832aff2e2695c2bbc0afd03dfb Mon Sep 17 00:00:00 2001 From: Peter Law Date: Thu, 1 Feb 2018 01:53:22 +0000 Subject: [PATCH 9/9] Filter chains can in fact be sequences --- stdlib/3.3/lzma.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3.3/lzma.pyi b/stdlib/3.3/lzma.pyi index 9ca91e1c10a1..e858d031f41f 100644 --- a/stdlib/3.3/lzma.pyi +++ b/stdlib/3.3/lzma.pyi @@ -1,6 +1,6 @@ import io import sys -from typing import Any, BinaryIO, IO, List, Mapping, Optional, Union +from typing import Any, BinaryIO, IO, List, Mapping, Optional, Sequence, Union if sys.version_info >= (3, 6): from os import PathLike @@ -8,7 +8,7 @@ if sys.version_info >= (3, 6): else: _PathOrFile = Union[str, bytes, IO[Any]] -_FilterChain = List[Mapping[str, Any]] +_FilterChain = Sequence[Mapping[str, Any]] FORMAT_AUTO: int FORMAT_XZ: int