Make typing.IO inherit Iterator, not Iterable (#502)

In Python, it's possible to use the `next` builtin method on file
objects produced by `open`. This change modifies `typing.IO` so this
usage will successfully typecheck.
This commit is contained in:
Michael Lee
2016-08-27 23:31:16 -07:00
committed by Guido van Rossum
parent 5e5b3726f2
commit 97bc450acd
2 changed files with 6 additions and 2 deletions

View File

@@ -208,7 +208,7 @@ Text = unicode
TYPE_CHECKING = True
class IO(Iterable[AnyStr], Generic[AnyStr]):
class IO(Iterator[AnyStr], Generic[AnyStr]):
# TODO detach
# TODO use abstract properties
@property
@@ -250,6 +250,8 @@ class IO(Iterable[AnyStr], Generic[AnyStr]):
@abstractmethod
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
@abstractmethod
def next(self) -> AnyStr: ...
@abstractmethod
def __iter__(self) -> Iterator[AnyStr]: ...
@abstractmethod