Skip to content

Commit

Permalink
Update mmap stubs for newer Python versions
Browse files Browse the repository at this point in the history
Based on the Python stdlib documentation:
- Since Python 3.5, mmap.{find,rfind,write} all accept any bytes-like.
  I've used the _typeshed.ReadableBuffer alias defined in python#4232.
- Since Python 3.6, mmap.write returns the number of bytes written.
- Since Python 3.3, mmap.read allows None as the parameter; while in
  Python 2 the argument cannot be omitted.
  • Loading branch information
bmerry committed Jun 19, 2020
1 parent e05fbab commit cdbbf03
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions stdlib/2and3/mmap.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from typing import (Optional, Sequence, Union, Generic, overload,
Iterable, Iterator, Sized, ContextManager, AnyStr)
from _typeshed import ReadableBuffer

ACCESS_DEFAULT: int
ACCESS_READ: int
Expand Down Expand Up @@ -40,14 +41,20 @@ class _mmap(Generic[AnyStr]):
else:
def flush(self, offset: int = ..., size: int = ...) -> int: ...
def move(self, dest: int, src: int, count: int) -> None: ...
def read(self, n: int = ...) -> AnyStr: ...
if sys.version_info >= (3, 3):
def read(self, n: int = ...) -> AnyStr: ...
else:
def read(self, n: int) -> AnyStr: ...
def read_byte(self) -> AnyStr: ...
def readline(self) -> AnyStr: ...
def resize(self, newsize: int) -> None: ...
def seek(self, pos: int, whence: int = ...) -> None: ...
def size(self) -> int: ...
def tell(self) -> int: ...
def write(self, bytes: AnyStr) -> None: ...
if sys.version_info >= (3, 6):
def write(self, bytes: AnyStr) -> int: ...
else:
def write(self, bytes: AnyStr) -> None: ...
def write_byte(self, byte: AnyStr) -> None: ...
def __len__(self) -> int: ...

Expand All @@ -56,7 +63,15 @@ if sys.version_info >= (3,):
closed: bool
if sys.version_info >= (3, 8) and sys.platform != "win32":
def madvise(self, option: int, start: int = ..., length: int = ...) -> None: ...
def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ...
if sys.version_info >= (3, 5):
def find(self, sub: ReadableBuffer, start: int = ..., stop: int = ...) -> int: ...
def rfind(self, sub: ReadableBuffer, start: int = ..., stop: int = ...) -> int: ...
else:
def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ...
if sys.version_info >= (3, 6):
def write(self, bytes: ReadableBuffer) -> int: ...
elif sys.version_info >= (3, 5):
def write(self, bytes: ReadableBuffer) -> None: ...
@overload
def __getitem__(self, index: int) -> int: ...
@overload
Expand Down

0 comments on commit cdbbf03

Please sign in to comment.