Skip to content

Commit

Permalink
Accept mmap objects in places where bytearray is expected.
Browse files Browse the repository at this point in the history
Fixes #1467.
  • Loading branch information
jonathanslenders authored May 27, 2019
1 parent 020449a commit 63007af
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions stdlib/2and3/mmap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class _mmap(Generic[AnyStr]):
def __len__(self) -> int: ...

if sys.version_info >= (3,):
class mmap(_mmap, ContextManager[mmap], Iterable[bytes], Sized):
# Inherit both `bytearray` and `Iterable[bytes]` because mmap can be used
# in places where bytearray is expected, like re.match, while iterating
# through `mmap` yields `bytes` objects, not integers.
class mmap(_mmap, ContextManager[mmap], bytearray, Iterable[bytes], Sized):
closed: bool
def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ...
@overload
Expand All @@ -65,7 +68,7 @@ if sys.version_info >= (3,):
# __len__, so we claim that there is also an __iter__ to help type checkers.
def __iter__(self) -> Iterator[bytes]: ...
else:
class mmap(_mmap, Sequence[bytes]):
class mmap(_mmap, bytes):
def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ...
def __getitem__(self, index: Union[int, slice]) -> bytes: ...
def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ...
Expand Down

0 comments on commit 63007af

Please sign in to comment.