Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some abstract classes in Python 2 #2240

Merged
merged 1 commit into from
Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/2/__builtin__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
1 change: 1 addition & 0 deletions stdlib/2/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down
8 changes: 6 additions & 2 deletions stdlib/2/cStringIO.pyi
Original file line number Diff line number Diff line change
@@ -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.
Copy link
Member

@ilevkivskyi ilevkivskyi Jun 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a good idea. Some other languages have Reader and Writer classes. We can have structure like this:

class Reader(Generic[AnyStr]):
    # basic read methods
class Writer(Generic[AnyStr]):
    # basic write methods
class IO(Reader[AnyStr], Writer[AnyStr]):
    # some additional rarely used methods

Do we have an issue to track this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, feel free to open one. I'm a bit hesitant to fiddle with the IO class hierarchy though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, opened python/typing#564


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
Expand All @@ -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: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/2/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions third_party/2/enum.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down