Make IOBase.__enter__ return the same type as self. Fixes #1540. (#1541)

This commit is contained in:
Evan Krall
2017-08-11 16:06:07 -07:00
committed by Guido van Rossum
parent 10a3e43a19
commit 9db63fee91

View File

@@ -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):