Fix memoryview stub (#651)

Fixes python/mypy#2390
This commit is contained in:
Guido van Rossum
2016-11-02 17:18:44 -07:00
committed by GitHub
parent 5a2a46d3bd
commit 7c20adb715

View File

@@ -1,7 +1,7 @@
# Stubs for builtins (Python 3)
from typing import (
TypeVar, Iterator, Iterable, overload,
TypeVar, Iterator, Iterable, overload, Container,
Sequence, MutableSequence, Mapping, MutableMapping, Tuple, List, Any, Dict, Callable, Generic,
Set, AbstractSet, MutableSet, Sized, Reversible, SupportsInt, SupportsFloat, SupportsBytes,
SupportsAbs, SupportsRound, IO, Union, ItemsView, KeysView, ValuesView, ByteString, Optional
@@ -422,12 +422,41 @@ class bytearray(MutableSequence[int], ByteString):
def __gt__(self, x: bytes) -> bool: ...
def __ge__(self, x: bytes) -> bool: ...
class memoryview():
# TODO arg can be any obj supporting the buffer protocol
def __init__(self, b: bytearray) -> None: ...
class memoryview(Sized, Container[bytes]):
format = ... # type: str
itemsize = ... # type: int
shape = ... # type: Optional[Tuple[int, ...]]
strides = ... # type: Optional[Tuple[int, ...]]
suboffsets = ... # type: Optional[Tuple[int, ...]]
readonly = ... # type: bool
ndim = ... # type: int
def __init__(self, obj: Union[str, bytes, bytearray, memoryview]) -> None: ...
@overload
def __getitem__(self, i: int) -> int: ...
@overload
def __getitem__(self, s: slice) -> memoryview: ...
def __contains__(self, x: object) -> bool: ...
def __iter__(self) -> Iterator[bytes]: ...
def __len__(self) -> int: ...
@overload
def __setitem__(self, i: int, o: bytes) -> None: ...
@overload
def __setitem__(self, s: slice, o: Sequence[bytes]) -> None: ...
@overload
def __setitem__(self, s: slice, o: memoryview) -> None: ...
def tobytes(self) -> bytes: ...
def tolist(self) -> List[int]: ...
if sys.version_info >= (3, 5):
def hex(self) -> str: ...
class bool(int, SupportsInt, SupportsFloat):
def __init__(self, o: object = ...) -> None: ...
@@ -694,7 +723,6 @@ def map(func: Callable[[_T1, _T2], _S], iter1: Iterable[_T1],
def max(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload
def max(iterable: Iterable[_T], key: Callable[[_T], Any] = ..., default:_T = ...) -> _T: ...
# TODO memoryview
@overload
def min(arg1: _T, arg2: _T, *args: _T, key: Callable[[_T], Any] = ...) -> _T: ...
@overload