Fix abstract classes in 2.7 (#2247)

Part of #1476.
This commit is contained in:
Jelle Zijlstra
2018-06-17 09:21:17 -07:00
committed by Ivan Levkivskyi
parent 6b36b1befe
commit 8084dc1c1f
6 changed files with 55 additions and 34 deletions

View File

@@ -38,8 +38,12 @@ class _IOBase(BinaryIO):
def writelines(self, lines: Iterable[bytes]) -> None: ...
# The return type of readline[s]() and next() is determined by that of read():
def readline(self, limit: int = ...) -> bytes: ...
def readlines(self, hint: int = ...) -> list[bytes]: ...
def readlines(self, hint: int = ...) -> List[bytes]: ...
def next(self) -> bytes: ...
# These don't actually exist but we need to pretend that it does
# so that this class is concrete.
def write(self, s: bytes) -> int: ...
def read(self, n: int = ...) -> bytes: ...
class _BufferedIOBase(_IOBase):
def read1(self, n: int) -> bytes: ...

View File

@@ -1,11 +1,9 @@
# Stubs for multiprocessing.pool (Python 2)
from typing import (
Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List,
TypeVar,
Any, Callable, ContextManager, Iterable, Optional, Dict, List,
TypeVar, Iterator,
)
_T = TypeVar('_T', bound='Pool')
_T = TypeVar('_T', bound=Pool)
class AsyncResult():
def get(self, timeout: Optional[float] = ...) -> Any: ...
@@ -14,6 +12,7 @@ class AsyncResult():
def successful(self) -> bool: ...
class IMapIterator(Iterable[Any]):
def __iter__(self) -> Iterator[Any]: ...
def next(self, timeout: Optional[float] = ...) -> Any: ...
class Pool(ContextManager[Pool]):

View File

@@ -75,6 +75,11 @@ X_OK: int
class _Environ(MutableMapping[AnyStr, AnyStr], Generic[AnyStr]):
def copy(self) -> Dict[AnyStr, AnyStr]: ...
def __delitem__(self, key: AnyStr) -> None: ...
def __getitem__(self, key: AnyStr) -> AnyStr: ...
def __setitem__(self, key: AnyStr, value: AnyStr) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
def __len__(self) -> int: ...
environ: _Environ[str]
if sys.version_info >= (3, 2):

View File

@@ -1,17 +1,6 @@
# Stubs for tempfile
# Ron Murawski <ron@horizonchess.com>
# based on http: //docs.python.org/3.3/library/tempfile.html
# Adapted for Python 2.7 by Michal Pokorny
# TODO: Don't use basestring. Use Union[str, bytes] or AnyStr for arguments.
# Avoid using Union[str, bytes] for return values, as it implies that
# an isinstance() check will often be required, which is inconvenient.
from typing import Tuple, IO, Union, AnyStr, Any, overload, Iterator, List, Type, Optional
import thread
import random
from typing import Tuple, IO, Union, AnyStr, Any, overload, Iterator, List, Iterable, Optional
from thread import LockType
from random import Random
TMP_MAX = ... # type: int
tempdir = ... # type: str
@@ -19,28 +8,46 @@ template = ... # type: str
_name_sequence = ... # type: Optional[_RandomNameSequence]
class _RandomNameSequence:
_rng = ... # type: random.Random
_rng_pid = ... # type: int
characters = ... # type: str
mutex = ... # type: thread.LockType
rng = ... # type: random.Random
def __iter__(self) -> "_RandomNameSequence": ...
characters: str = ...
mutex: LockType
@property
def rng(self) -> Random: ...
def __iter__(self) -> _RandomNameSequence: ...
def next(self) -> str: ...
# from os.path:
def normcase(self, path: AnyStr) -> AnyStr: ...
class _TemporaryFileWrapper(IO[str]):
close_called = ... # type: bool
delete = ... # type: bool
file = ... # type: IO
name = ... # type: Any
def __init__(self, file: IO, name, delete: bool = ...) -> None: ...
delete: bool
file: IO
name: Any
def __init__(self, file: IO, name: Any, delete: bool = ...) -> None: ...
def __del__(self) -> None: ...
def __enter__(self) -> "_TemporaryFileWrapper": ...
def __enter__(self) -> _TemporaryFileWrapper: ...
def __exit__(self, exc, value, tb) -> bool: ...
def __getattr__(self, name: unicode) -> Any: ...
def close(self) -> None: ...
def unlink(self, path: unicode) -> None: ...
# These methods don't exist directly on this object, but
# are delegated to the underlying IO object through __getattr__.
# We need to add them here so that this class is concrete.
def __iter__(self) -> Iterator[str]: ...
def fileno(self) -> int: ...
def flush(self) -> None: ...
def isatty(self) -> bool: ...
def next(self) -> str: ...
def read(self, n: int = ...) -> str: ...
def readable(self) -> bool: ...
def readline(self, limit: int = ...) -> str: ...
def readlines(self, hint: int = ...) -> List[str]: ...
def seek(self, offset: int, whence: int = ...) -> int: ...
def seekable(self) -> bool: ...
def tell(self) -> int: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
def writable(self) -> bool: ...
def write(self, s: str) -> int: ...
def writelines(self, lines: Iterable[str]) -> None: ...
# TODO text files

View File

@@ -23,7 +23,10 @@ class Dialect:
class _reader(Iterator[List[str]]):
dialect = ... # type: Dialect
line_num = ... # type: int
def __next__(self) -> List[str]: ...
if sys.version_info >= (3, 0):
def __next__(self) -> List[str]: ...
else:
def next(self) -> List[str]: ...
class _writer:
dialect = ... # type: Dialect

View File

@@ -163,7 +163,10 @@ class Cursor(Iterator[Any]):
def setinputsizes(self, *args, **kwargs): ...
def setoutputsize(self, *args, **kwargs): ...
def __iter__(self) -> Cursor: ...
def __next__(self) -> Any: ...
if sys.version_info >= (3, 0):
def __next__(self) -> Any: ...
else:
def next(self) -> Any: ...
class DataError(DatabaseError): ...