mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 21:14:48 +08:00
fix the stub files for the stdlib mmap module (#5705)
In Python 3: - The `mmap` type is `Iterable[int]`, not `Iterable[bytes]`. - The `read_byte` method returns an `int`, and the `write_byte` method only accepts an `int` as its first and only argument. - The `__setitem__` method accepts any `ReadableBuffer` object, not just `bytes`. In both Python 2 and 3: - The `__delitem__` method always raises a `TypeError`, so the proper return type is `NoReturn`. - The `mmap` type isn't generic, so I've simplified the stubs by removing the unnecessary `_mmap` class.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from typing import AnyStr, Generic, Optional, Sequence, Union
|
||||
from typing import NoReturn, Optional, Sequence, Union
|
||||
|
||||
ACCESS_DEFAULT: int
|
||||
ACCESS_READ: int
|
||||
@@ -23,7 +23,7 @@ if sys.platform != "win32":
|
||||
|
||||
PAGESIZE: int
|
||||
|
||||
class _mmap(Generic[AnyStr]):
|
||||
class mmap(Sequence[bytes]):
|
||||
if sys.platform == "win32":
|
||||
def __init__(
|
||||
self, fileno: int, length: int, tagname: Optional[str] = ..., access: int = ..., offset: int = ...
|
||||
@@ -35,21 +35,19 @@ class _mmap(Generic[AnyStr]):
|
||||
def close(self) -> None: ...
|
||||
def flush(self, offset: int = ..., size: int = ...) -> int: ...
|
||||
def move(self, dest: int, src: int, count: int) -> None: ...
|
||||
def read_byte(self) -> AnyStr: ...
|
||||
def readline(self) -> AnyStr: ...
|
||||
def read_byte(self) -> bytes: ...
|
||||
def readline(self) -> bytes: ...
|
||||
def resize(self, newsize: int) -> None: ...
|
||||
def seek(self, pos: int, whence: int = ...) -> None: ...
|
||||
def size(self) -> int: ...
|
||||
def tell(self) -> int: ...
|
||||
def write_byte(self, byte: AnyStr) -> None: ...
|
||||
def write_byte(self, byte: bytes) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
class mmap(_mmap[bytes], Sequence[bytes]):
|
||||
def find(self, string: bytes, start: int = ..., end: int = ...) -> int: ...
|
||||
def rfind(self, string: bytes, start: int = ..., stop: int = ...) -> int: ...
|
||||
def read(self, num: int) -> bytes: ...
|
||||
def write(self, string: bytes) -> None: ...
|
||||
def __getitem__(self, index: Union[int, slice]) -> bytes: ...
|
||||
def __getslice__(self, i: Optional[int], j: Optional[int]) -> bytes: ...
|
||||
def __delitem__(self, index: Union[int, slice]) -> None: ...
|
||||
def __delitem__(self, index: Union[int, slice]) -> NoReturn: ...
|
||||
def __setitem__(self, index: Union[int, slice], object: bytes) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user