From 451deba4efce916da8effd8e01411e0a73d632a7 Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Fri, 15 Jun 2018 07:51:56 -0700 Subject: [PATCH] memoryview type information inconsistent with runtime behavior (#2230) memoryview type information inconsistent with documentation of typing module. `memoryview` should be a ByteString like the docs say. `memoryview.__init__` does not accept str, and instead of a union it should just accept ByteString. `memoryview.__iter__` returns an Iterator[int] not bytes. --- stdlib/3/builtins.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/stdlib/3/builtins.pyi b/stdlib/3/builtins.pyi index eb6e27b5b..b77dcc0ee 100644 --- a/stdlib/3/builtins.pyi +++ b/stdlib/3/builtins.pyi @@ -358,7 +358,7 @@ class bytes(ByteString): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[bytes]) -> bytes: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytes: ... def ljust(self, width: int, fillchar: bytes = ...) -> bytes: ... def lower(self) -> bytes: ... def lstrip(self, chars: Optional[bytes] = ...) -> bytes: ... @@ -451,7 +451,7 @@ class bytearray(MutableSequence[int], ByteString): def isspace(self) -> bool: ... def istitle(self) -> bool: ... def isupper(self) -> bool: ... - def join(self, iterable: Iterable[bytes]) -> bytearray: ... + def join(self, iterable: Iterable[Union[ByteString, memoryview]]) -> bytearray: ... def ljust(self, width: int, fillchar: bytes = ...) -> bytearray: ... def lower(self) -> bytearray: ... def lstrip(self, chars: Optional[bytes] = ...) -> bytearray: ... @@ -514,7 +514,7 @@ class bytearray(MutableSequence[int], ByteString): def __gt__(self, x: bytes) -> bool: ... def __ge__(self, x: bytes) -> bool: ... -class memoryview(Sized, Container[bytes]): +class memoryview(Sized, Container[int]): format = ... # type: str itemsize = ... # type: int shape = ... # type: Optional[Tuple[int, ...]] @@ -523,7 +523,7 @@ class memoryview(Sized, Container[bytes]): readonly = ... # type: bool ndim = ... # type: int - def __init__(self, obj: Union[str, bytes, bytearray, memoryview]) -> None: ... + def __init__(self, obj: Union[bytes, bytearray, memoryview]) -> None: ... @overload def __getitem__(self, i: int) -> int: ... @@ -531,7 +531,7 @@ class memoryview(Sized, Container[bytes]): def __getitem__(self, s: slice) -> memoryview: ... def __contains__(self, x: object) -> bool: ... - def __iter__(self) -> Iterator[bytes]: ... + def __iter__(self) -> Iterator[int]: ... def __len__(self) -> int: ... @overload