diff --git a/stdlib/2and3/mmap.pyi b/stdlib/2and3/mmap.pyi index 87b1f048d..933723bdb 100644 --- a/stdlib/2and3/mmap.pyi +++ b/stdlib/2and3/mmap.pyi @@ -1,21 +1,6 @@ -# Stubs for mmap - import sys -from types import TracebackType -from typing import (Optional, Sequence, Union, Generic, TypeVar, overload, - Iterable, Iterator, Sized, Type) - - -_T = TypeVar('_T', str, bytes) - -# TODO already in PEP, have to get added to mypy -_C = TypeVar('_C') -class _ContextManager(Generic[_C]): - def __enter__(self) -> _C: ... - def __exit__(self, exc_type: Optional[Type[BaseException]], - exc_val: Optional[Exception], - exc_tb: Optional[TracebackType]) -> bool: ... - +from typing import (Optional, Sequence, Union, Generic, overload, + Iterable, Iterator, Sized, ContextManager, AnyStr) ACCESS_READ = ... # type: int ACCESS_WRITE = ... # type: int @@ -31,7 +16,7 @@ if sys.platform != 'win32': PAGESIZE = ... # type: int -class _mmap(Generic[_T]): +class _mmap(Generic[AnyStr]): if sys.platform == 'win32': def __init__(self, fileno: int, length: int, tagname: Optional[str] = ..., access: int = ..., @@ -42,23 +27,23 @@ class _mmap(Generic[_T]): prot: int = ..., access: int = ..., offset: int = ...) -> None: ... def close(self) -> None: ... - def find(self, sub: _T, + def find(self, sub: AnyStr, start: int = ..., end: int = ...) -> int: ... def flush(self, offset: int = ..., size: int = ...) -> int: ... def move(self, dest: int, src: int, count: int) -> None: ... - def read(self, n: int = ...) -> _T: ... - def read_byte(self) -> _T: ... - def readline(self) -> _T: ... + def read(self, n: int = ...) -> AnyStr: ... + def read_byte(self) -> AnyStr: ... + def readline(self) -> AnyStr: ... def resize(self, newsize: int) -> None: ... def seek(self, pos: int, whence: int = ...) -> None: ... def size(self) -> int: ... def tell(self) -> int: ... - def write(self, bytes: _T) -> None: ... - def write_byte(self, byte: _T) -> None: ... + def write(self, bytes: AnyStr) -> None: ... + def write_byte(self, byte: AnyStr) -> None: ... def __len__(self) -> int: ... if sys.version_info >= (3,): - class mmap(_mmap, _ContextManager[mmap], Iterable[bytes], Sized): + class mmap(_mmap, ContextManager[mmap], Iterable[bytes], Sized): closed = ... # type: bool def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ... @overload diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 4b1deb742..9d9351177 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -16,19 +16,13 @@ SEEK_END = ... # type: int open = builtins.open -# FIXME when mypy handle condtional, we can uncomment the next block and remove -# the temporary fix -# if sys.version_info >= (3, 3): -# BlockingIOError = BlockingIOError -# class UnsupportedOperation(OSError, ValueError): ... -# else: -# class BlockingIOError(IOError): -# characters_written = ... # type: int -# class UnsupportedOperation(IOError, ValueError): ... -class BlockingIOError(OSError): - characters_written = ... # type: int -class UnsupportedOperation(OSError, ValueError): ... - +if sys.version_info >= (3, 3): + BlockingIOError = builtins.BlockingIOError + class UnsupportedOperation(OSError, ValueError): ... +else: + class BlockingIOError(IOError): + characters_written: int + class UnsupportedOperation(IOError, ValueError): ... class IOBase: def __iter__(self) -> Iterator[bytes]: ... diff --git a/stdlib/3/typing.pyi b/stdlib/3/typing.pyi index b8d732749..e8d5b5bb2 100644 --- a/stdlib/3/typing.pyi +++ b/stdlib/3/typing.pyi @@ -116,9 +116,8 @@ class Generator(Iterator[_T_co], Generic[_T_co, _T_contra, _V_co]): def send(self, value: _T_contra) -> _T_co: ... @abstractmethod - def throw(self, typ: Type[BaseException], val: Optional[BaseException] = None, - # TODO: tb should be TracebackType but that's defined in types - tb: Any = None) -> None: ... + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: Optional[TracebackType] = ...) -> None: ... @abstractmethod def close(self) -> None: ... @@ -144,9 +143,8 @@ class Coroutine(Awaitable[_V_co], Generic[_T_co, _T_contra, _V_co]): def send(self, value: _T_contra) -> _T_co: ... @abstractmethod - def throw(self, typ: Type[BaseException], val: Optional[BaseException] = None, - # TODO: tb should be TracebackType but that's defined in types - tb: Any = None) -> None: ... + def throw(self, typ: Type[BaseException], val: Optional[BaseException] = ..., + tb: Optional[TracebackType] = ...) -> None: ... @abstractmethod def close(self) -> None: ... @@ -399,8 +397,7 @@ class IO(Iterator[AnyStr], Generic[AnyStr]): def __enter__(self) -> 'IO[AnyStr]': ... @abstractmethod def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], - # TODO: traceback should be TracebackType but that's defined in types - traceback: Optional[Any]) -> bool: ... + traceback: Optional[TracebackType]) -> bool: ... class BinaryIO(IO[bytes]): # TODO readinto diff --git a/stdlib/3/unittest/__init__.pyi b/stdlib/3/unittest/__init__.pyi index 68d1f56e8..f21bc5f13 100644 --- a/stdlib/3/unittest/__init__.pyi +++ b/stdlib/3/unittest/__init__.pyi @@ -16,10 +16,9 @@ _E = TypeVar('_E', bound=Exception) def expectedFailure(func: _FT) -> _FT: ... -# TODO: Once python/mypy#1551 is fixed, the following need _FT instead of Any -def skip(reason: str) -> Callable[[Any], Any]: ... -def skipIf(condition: object, reason: str) -> Callable[[Any], Any]: ... -def skipUnless(condition: object, reason: str) -> Callable[[Any], Any]: ... +def skip(reason: str) -> Callable[[_FT], _FT]: ... +def skipIf(condition: object, reason: str) -> Callable[[_FT], _FT]: ... +def skipUnless(condition: object, reason: str) -> Callable[[_FT], _FT]: ... class SkipTest(Exception): def __init__(self, reason: str) -> None: ...