Skip to content

Commit 63007af

Browse files
Accept mmap objects in places where bytearray is expected.
Fixes #1467.
1 parent 020449a commit 63007af

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stdlib/2and3/mmap.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class _mmap(Generic[AnyStr]):
4949
def __len__(self) -> int: ...
5050

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

0 commit comments

Comments
 (0)