From 117ca4cc7bb793b7832ec4e4ec2f5cd81da9869a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 15 Jun 2018 19:44:21 -0700 Subject: [PATCH] fix some abstract classes in Python 2 Part of #1476. --- stdlib/2/__builtin__.pyi | 1 + stdlib/2/builtins.pyi | 1 + stdlib/2/cStringIO.pyi | 8 ++++++-- stdlib/2/typing.pyi | 2 +- third_party/2/enum.pyi | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/stdlib/2/__builtin__.pyi b/stdlib/2/__builtin__.pyi index 05bfc1e09384..ca6f15c84f00 100644 --- a/stdlib/2/__builtin__.pyi +++ b/stdlib/2/__builtin__.pyi @@ -1060,6 +1060,7 @@ class file(BinaryIO): @overload def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... def read(self, n: int = ...) -> str: ... def __enter__(self) -> BinaryIO: ... def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... diff --git a/stdlib/2/builtins.pyi b/stdlib/2/builtins.pyi index 05bfc1e09384..ca6f15c84f00 100644 --- a/stdlib/2/builtins.pyi +++ b/stdlib/2/builtins.pyi @@ -1060,6 +1060,7 @@ class file(BinaryIO): @overload def __init__(self, file: int, mode: str = ..., buffering: int = ...) -> None: ... def __iter__(self) -> Iterator[str]: ... + def next(self) -> str: ... def read(self, n: int = ...) -> str: ... def __enter__(self) -> BinaryIO: ... def __exit__(self, t: Optional[type] = ..., exc: Optional[BaseException] = ..., tb: Optional[Any] = ...) -> bool: ... diff --git a/stdlib/2/cStringIO.pyi b/stdlib/2/cStringIO.pyi index 462e6ae7fa0e..db67cda46887 100644 --- a/stdlib/2/cStringIO.pyi +++ b/stdlib/2/cStringIO.pyi @@ -1,12 +1,15 @@ # Stubs for cStringIO (Python 2.7) # See https://docs.python.org/2/library/stringio.html +from abc import ABCMeta from typing import overload, IO, List, Iterable, Iterator, Optional, Union from types import TracebackType # TODO the typing.IO[] generics should be split into input and output. -class InputType(IO[str], Iterator[str]): +# This class isn't actually abstract, but you can't instantiate it +# directly, so we might as well treat it as abstract in the stub. +class InputType(IO[str], Iterator[str], metaclass=ABCMeta): def getvalue(self) -> str: ... def close(self) -> None: ... @property @@ -23,7 +26,8 @@ class InputType(IO[str], Iterator[str]): def next(self) -> str: ... def reset(self) -> None: ... -class OutputType(IO[str], Iterator[str]): + +class OutputType(IO[str], Iterator[str], metaclass=ABCMeta): @property def softspace(self) -> int: ... def getvalue(self) -> str: ... diff --git a/stdlib/2/typing.pyi b/stdlib/2/typing.pyi index 44fd15c33d37..079b1476d780 100644 --- a/stdlib/2/typing.pyi +++ b/stdlib/2/typing.pyi @@ -349,7 +349,7 @@ class TextIO(IO[unicode]): @abstractmethod def __enter__(self) -> TextIO: ... -class ByteString(Sequence[int]): ... +class ByteString(Sequence[int], metaclass=ABCMeta): ... class Match(Generic[AnyStr]): pos = 0 diff --git a/third_party/2/enum.pyi b/third_party/2/enum.pyi index 9b7b7cbfb839..c4167786178b 100644 --- a/third_party/2/enum.pyi +++ b/third_party/2/enum.pyi @@ -15,6 +15,7 @@ class EnumMeta(ABCMeta, Iterable[Enum], Sized, Reversible[Enum], Container[Enum] def __getitem__(self: Type[_T], name: str) -> _T: ... @property def __members__(self: Type[_T]) -> Mapping[str, _T]: ... + def __len__(self) -> int: ... class Enum(metaclass=EnumMeta): def __new__(cls: Type[_T], value: Any) -> _T: ...