From 0080017d02b92b4ccbf1aa6d869e9bf0d93622c4 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 13 Nov 2017 06:55:43 -0800 Subject: [PATCH] fill out bz2 stub (#1728) - add a default value to ... - add some missing version checks - add some missing arguments --- stdlib/2and3/bz2.pyi | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/stdlib/2and3/bz2.pyi b/stdlib/2and3/bz2.pyi index a558b0553..12cb9cc10 100644 --- a/stdlib/2and3/bz2.pyi +++ b/stdlib/2and3/bz2.pyi @@ -1,20 +1,29 @@ -# Stubs for bz2 +import sys +from typing import Any, BinaryIO, IO, Optional, Union -from typing import Any, BinaryIO, TextIO, IO, 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 def compress(data: bytes, compresslevel: int = ...) -> bytes: ... def decompress(data: bytes) -> bytes: ... -def open(filename: Union[str, bytes, IO[Any]], - mode: str = ..., - encoding: Optional[str] = ..., - errors: Optional[str] = ..., - newline: Optional[str] = ...) -> IO[Any]: ... +if sys.version_info >= (3, 3): + def open(filename: _PathOrFile, + mode: str = ..., + compresslevel: int = ..., + encoding: Optional[str] = ..., + errors: Optional[str] = ..., + newline: Optional[str] = ...) -> IO[Any]: ... class BZ2File(BinaryIO): def __init__(self, - filename: Union[str, bytes, IO[Any]], - mode: str = "r", + filename: _PathOrFile, + mode: str = ..., buffering: Optional[Any] = ..., compresslevel: int = ...) -> None: ... @@ -24,10 +33,15 @@ class BZ2Compressor(object): def flush(self) -> bytes: ... class BZ2Decompressor(object): - def decompress(self, data: bytes) -> bytes: ... - @property - def eof(self) -> bool: ... - @property - def needs_input(self) -> bool: ... + if sys.version_info >= (3, 5): + def decompress(self, data: bytes, max_length: int = ...) -> bytes: ... + else: + def decompress(self, data: bytes) -> bytes: ... + if sys.version_info >= (3, 3): + @property + def eof(self) -> bool: ... + if sys.version_info >= (3, 5): + @property + def needs_input(self) -> bool: ... @property def unused_data(self) -> bytes: ...