mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-20 19:01:15 +08:00
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:
committed by
Guido van Rossum
parent
5e5b3726f2
commit
97bc450acd
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user