From 9db63fee915c2ec226444ce3b05f74a4e60e411e Mon Sep 17 00:00:00 2001 From: Evan Krall Date: Fri, 11 Aug 2017 16:06:07 -0700 Subject: [PATCH] Make IOBase.__enter__ return the same type as self. Fixes #1540. (#1541) --- stdlib/3/io.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index c068d2cb2..20c63efa5 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -5,6 +5,7 @@ import builtins import codecs import sys from types import TracebackType +from typing import TypeVar DEFAULT_BUFFER_SIZE = ... # type: int @@ -12,6 +13,8 @@ SEEK_SET = ... # type: int SEEK_CUR = ... # type: int SEEK_END = ... # type: int +_T = TypeVar('_T', bound='IOBase') + open = builtins.open if sys.version_info >= (3, 3): @@ -25,7 +28,7 @@ else: class IOBase: def __iter__(self) -> Iterator[bytes]: ... def __next__(self) -> bytes: ... - def __enter__(self) -> 'IOBase': ... + def __enter__(self: _T) -> _T: ... def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], exc_tb: Optional[TracebackType]) -> bool: ... def close(self) -> None: ... @@ -164,7 +167,6 @@ class TextIOBase(IOBase): newlines = ... # type: Union[str, Tuple[str, ...], None] def __iter__(self) -> Iterator[str]: ... # type: ignore def __next__(self) -> str: ... # type: ignore - def __enter__(self) -> 'TextIOBase': ... def detach(self) -> IOBase: ... def write(self, s: str) -> int: ... if sys.version_info >= (3, 4):