diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index 4d97765e7..55c7e8fa2 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -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: ... diff --git a/stdlib/2/multiprocessing/pool.pyi b/stdlib/2/multiprocessing/pool.pyi index 57a628d33..ac8ec4216 100644 --- a/stdlib/2/multiprocessing/pool.pyi +++ b/stdlib/2/multiprocessing/pool.pyi @@ -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]): diff --git a/stdlib/2/os/__init__.pyi b/stdlib/2/os/__init__.pyi index 6024eab86..43e1cf23e 100644 --- a/stdlib/2/os/__init__.pyi +++ b/stdlib/2/os/__init__.pyi @@ -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): diff --git a/stdlib/2/tempfile.pyi b/stdlib/2/tempfile.pyi index 15eda96f9..c19dbf179 100644 --- a/stdlib/2/tempfile.pyi +++ b/stdlib/2/tempfile.pyi @@ -1,17 +1,6 @@ -# Stubs for tempfile -# Ron Murawski - -# 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 diff --git a/stdlib/2and3/_csv.pyi b/stdlib/2and3/_csv.pyi index 59d895d49..9f6a9e86e 100644 --- a/stdlib/2and3/_csv.pyi +++ b/stdlib/2and3/_csv.pyi @@ -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 diff --git a/stdlib/2and3/sqlite3/dbapi2.pyi b/stdlib/2and3/sqlite3/dbapi2.pyi index e80733d68..a131fc27e 100644 --- a/stdlib/2and3/sqlite3/dbapi2.pyi +++ b/stdlib/2and3/sqlite3/dbapi2.pyi @@ -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): ...