Skip to content

Accept mmap objects in places where bytearray is expected. #3014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions stdlib/2and3/mmap.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from typing import (Optional, Sequence, Union, Generic, overload,
Iterable, Iterator, Sized, ContextManager, AnyStr)
from typing import (Optional, Union, Generic, overload, Iterable,
Iterator, Sized, ContextManager, AnyStr)

ACCESS_DEFAULT: int
ACCESS_READ: int
Expand Down 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