From 97bc450acd60c1bcdafef3ce8fbe3b95a9c0cac3 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Sat, 27 Aug 2016 23:31:16 -0700 Subject: [PATCH] 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. --- stdlib/2.7/typing.pyi | 4 +++- stdlib/3/typing.pyi | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/stdlib/2.7/typing.pyi b/stdlib/2.7/typing.pyi index dc1497c6e..5e0906e0d 100644 --- a/stdlib/2.7/typing.pyi +++ b/stdlib/2.7/typing.pyi @@ -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 diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index e40ff42d2..438d2648b 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -267,7 +267,7 @@ Text = str TYPE_CHECKING = True -class IO(Iterable[AnyStr], Generic[AnyStr]): +class IO(Iterator[AnyStr], Generic[AnyStr]): # TODO detach # TODO use abstract properties @property @@ -310,6 +310,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