From ccf477e64c98820a55109eb3f265db2dfd17c986 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 22 Jun 2021 07:46:08 -0700 Subject: [PATCH 1/2] Make `ZipFile.__enter__` return self --- stdlib/zipfile.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index b43ff218c062..e3192ce280c0 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -2,9 +2,10 @@ import io import sys from _typeshed import StrPath from types import TracebackType -from typing import IO, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Tuple, Type, Union, overload +from typing import IO, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal +_T = TypeVar("_T") _DateTuple = Tuple[int, int, int, int, int, int] class BadZipFile(Exception): ... @@ -128,7 +129,7 @@ class ZipFile: def __init__( self, file: Union[StrPath, IO[bytes]], mode: str = ..., compression: int = ..., allowZip64: bool = ... ) -> None: ... - def __enter__(self) -> ZipFile: ... + def __enter__(self: _T) -> _T: ... def __exit__( self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType] ) -> None: ... From a5511354ddc05f5773ea3fb2b3d92be0976c6f78 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 22 Jun 2021 07:51:28 -0700 Subject: [PATCH 2/2] black --- stdlib/zipfile.pyi | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/stdlib/zipfile.pyi b/stdlib/zipfile.pyi index e3192ce280c0..8f3c2bef0a68 100644 --- a/stdlib/zipfile.pyi +++ b/stdlib/zipfile.pyi @@ -2,7 +2,22 @@ import io import sys from _typeshed import StrPath from types import TracebackType -from typing import IO, Callable, Dict, Iterable, Iterator, List, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union, overload +from typing import ( + IO, + Callable, + Dict, + Iterable, + Iterator, + List, + Optional, + Protocol, + Sequence, + Tuple, + Type, + TypeVar, + Union, + overload, +) from typing_extensions import Literal _T = TypeVar("_T")