Skip to content

Commit 0fea15e

Browse files
tharvikmatthiaskramm
authored andcommitted
Add mmap (#412)
* py3 done * have to have specific version, to much changes * py2 done * merge py2 and py3 version * fix duplicate definition in mypy * apply version specific def * rename ContextManager, single line for import
1 parent 6c6f5f1 commit 0fea15e

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

stdlib/2and3/mmap.pyi

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Stubs for mmap
2+
3+
from typing import Optional, Sequence, Union, Generic, TypeVar, overload
4+
import sys
5+
6+
7+
_T = TypeVar('_T', str, bytes)
8+
9+
# TODO already in PEP, have to get added to mypy
10+
from typing import Type
11+
from types import TracebackType
12+
_C = TypeVar('_C')
13+
class _ContextManager(Generic[_C]):
14+
def __enter__(self) -> _C: ...
15+
def __exit__(self, exc_type: Optional[Type[BaseException]],
16+
exc_val: Optional[Exception],
17+
exc_tb: Optional[TracebackType]) -> bool: ...
18+
19+
20+
ACCESS_READ = ... # type: int
21+
ACCESS_WRITE = ... # type: int
22+
ACCESS_COPY = ... # type: int
23+
24+
ALLOCATIONGRANULARITY = ... # type: int
25+
26+
if sys.platform != 'win32':
27+
MAP_PRIVATE = ... # type: int
28+
MAP_SHARED = ... # type: int
29+
PROT_READ = ... # type: int
30+
PROT_WRITE = ... # type: int
31+
32+
PAGESIZE = ... # type: int
33+
34+
class _mmap(Generic[_T]):
35+
if sys.platform == 'win32':
36+
def __init__(self, fileno: int, length: int,
37+
tagname: Optional[str] = ..., access: int = ...,
38+
offset: int = ...) -> None: ...
39+
else:
40+
def __init__(self, # type: ignore
41+
fileno: int, length: int, flags: int = ...,
42+
prot: int = ..., access: int = ...,
43+
offset: int = ...) -> None: ...
44+
def close(self) -> None: ...
45+
def find(self, sub: _T,
46+
start: int = ..., end: int = ...) -> int: ...
47+
def flush(self, offset: int = ..., size: int = ...) -> int: ...
48+
def move(self, dest: int, src: int, count: int) -> None: ...
49+
def read(self, n: int = ...) -> _T: ...
50+
def read_byte(self) -> _T: ...
51+
def readline(self) -> _T: ...
52+
def resize(self, newsize: int) -> None: ...
53+
def seek(self, pos: int, whence: int = ...) -> None: ...
54+
def size(self) -> int: ...
55+
def tell(self) -> int: ...
56+
def write(self, bytes: _T) -> None: ...
57+
def write_byte(self, byte: _T) -> None: ...
58+
def __len__(self) -> int: ...
59+
60+
if sys.version_info >= (3,):
61+
class mmap(_mmap, _ContextManager[mmap], Sequence[bytes]):
62+
closed = ... # type: bool
63+
def rfind(self, sub: bytes, start: int = ..., stop: int = ...) -> int: ...
64+
@overload # type: ignore
65+
def __getitem__(self, index: int) -> int: ...
66+
@overload
67+
def __getitem__(self, index: slice) -> bytes: ...
68+
def __delitem__(self, index: Union[int, slice]) -> None: ...
69+
@overload
70+
def __setitem__(self, index: int, object: int) -> None: ...
71+
@overload
72+
def __setitem__(self, index: slice, object: bytes) -> None: ...
73+
else:
74+
class mmap(_mmap, Sequence[str]):
75+
def rfind(self, string: str, start: int = ..., stop: int = ...) -> int: ...
76+
def __getitem__(self, index: Union[int, slice]) -> str: ...
77+
def __delitem__(self, index: Union[int, slice]) -> None: ...
78+
def __setitem__(self, index: Union[int, slice], object: str) -> None: ...

0 commit comments

Comments
 (0)