diff --git a/stdlib/2and3/bz2.pyi b/stdlib/2and3/bz2.pyi index 77658a793..629ecfb5d 100644 --- a/stdlib/2and3/bz2.pyi +++ b/stdlib/2and3/bz2.pyi @@ -1,7 +1,7 @@ import io import sys from os.path import _PathType -from typing import IO, Any, Optional, TextIO, Union, overload +from typing import IO, Any, Optional, TextIO, Union, overload, TypeVar if sys.version_info >= (3, 8): from typing import Literal @@ -9,6 +9,7 @@ else: from typing_extensions import Literal _PathOrFile = Union[_PathType, IO[bytes]] +_T = TypeVar("_T") def compress(data: bytes, compresslevel: int = ...) -> bytes: ... def decompress(data: bytes) -> bytes: ... @@ -44,7 +45,8 @@ if sys.version_info >= (3, 3): newline: Optional[str] = ..., ) -> Union[BZ2File, TextIO]: ... -class BZ2File(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#5027 +class BZ2File(io.BufferedIOBase, IO[bytes]): + def __enter__(self: _T) -> _T: ... if sys.version_info >= (3, 9): def __init__(self, filename: _PathOrFile, diff --git a/stdlib/3/lzma.pyi b/stdlib/3/lzma.pyi index f192c4362..8755ec807 100644 --- a/stdlib/3/lzma.pyi +++ b/stdlib/3/lzma.pyi @@ -1,7 +1,7 @@ import io import sys from os.path import _PathType -from typing import IO, Any, Mapping, Optional, Sequence, TextIO, Union, overload +from typing import IO, Any, Mapping, Optional, Sequence, TextIO, TypeVar, Union, overload if sys.version_info >= (3, 8): from typing import Literal @@ -14,6 +14,7 @@ _OpenTextWritingMode = Literal["wt", "xt", "at"] _PathOrFile = Union[_PathType, IO[bytes]] _FilterChain = Sequence[Mapping[str, Any]] +_T = TypeVar("_T") FORMAT_AUTO: int FORMAT_XZ: int @@ -69,7 +70,7 @@ class LZMACompressor(object): class LZMAError(Exception): ... -class LZMAFile(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#5027 +class LZMAFile(io.BufferedIOBase, IO[bytes]): def __init__( self, filename: Optional[_PathOrFile] = ..., @@ -80,6 +81,7 @@ class LZMAFile(io.BufferedIOBase, IO[bytes]): # type: ignore # python/mypy#502 preset: Optional[int] = ..., filters: Optional[_FilterChain] = ..., ) -> None: ... + def __enter__(self: _T) -> _T: ... def close(self) -> None: ... @property def closed(self) -> bool: ...