Skip to content

Commit f6b60cb

Browse files
rchen152matthiaskramm
authored andcommitted
A couple fixes to the io stubs. (#1811)
1. The 'name' argument to FileIO.init can be either a string or an integer: https://docs.python.org/2/library/io.html#io.FileIO 2. An mmap.mmap object can be used in most places that a bytearray can: https://docs.python.org/3.5/library/mmap.html
1 parent fb2c7b3 commit f6b60cb

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

stdlib/2/_io.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from typing import Any, AnyStr, BinaryIO, IO, Text, TextIO, Iterable, Iterator, List, Optional, Type, Tuple, TypeVar, Union
2+
from mmap import mmap
23
from types import TracebackType
34

5+
_bytearray_like = Union[bytearray, mmap]
6+
47
DEFAULT_BUFFER_SIZE = ... # type: int
58

69
class BlockingIOError(IOError):
@@ -41,7 +44,7 @@ class _IOBase(BinaryIO):
4144
class _BufferedIOBase(_IOBase):
4245
def read1(self, n: int) -> bytes: ...
4346
def read(self, size: int = ...) -> bytes: ...
44-
def readinto(self, buffer: bytearray) -> int: ...
47+
def readinto(self, buffer: _bytearray_like) -> int: ...
4548
def write(self, s: bytes) -> int: ...
4649
def detach(self) -> _IOBase: ...
4750

@@ -92,8 +95,8 @@ class _RawIOBase(_IOBase):
9295
class FileIO(_RawIOBase, BytesIO): # type: ignore # for __enter__
9396
mode = ... # type: str
9497
closefd = ... # type: bool
95-
def __init__(self, file: str, mode: str = ..., closefd: bool = ...) -> None: ...
96-
def readinto(self, buffer: bytearray)-> int: ...
98+
def __init__(self, file: Union[str, int], mode: str = ..., closefd: bool = ...) -> None: ...
99+
def readinto(self, buffer: _bytearray_like)-> int: ...
97100
def write(self, pbuf: str) -> int: ...
98101

99102
class IncrementalNewlineDecoder(object):

stdlib/3/http/client.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ if sys.version_info >= (3, 5):
8989
def __init__(self, sock: socket, debuglevel: int = ...,
9090
method: Optional[str] = ..., url: Optional[str] = ...) -> None: ...
9191
def read(self, amt: Optional[int] = ...) -> bytes: ...
92-
def readinto(self, b: bytearray) -> int: ...
9392
@overload
9493
def getheader(self, name: str) -> Optional[str]: ...
9594
@overload

stdlib/3/io.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ from typing import (
33
)
44
import builtins
55
import codecs
6+
from mmap import mmap
67
import sys
78
from types import TracebackType
89
from typing import TypeVar
910

11+
_bytearray_like = Union[bytearray, mmap]
12+
1013
DEFAULT_BUFFER_SIZE = ... # type: int
1114

1215
SEEK_SET = ... # type: int
@@ -65,10 +68,10 @@ class RawIOBase(IOBase):
6568

6669
class BufferedIOBase(IOBase):
6770
def detach(self) -> RawIOBase: ...
68-
def readinto(self, b: bytearray) -> int: ...
71+
def readinto(self, b: _bytearray_like) -> int: ...
6972
def write(self, b: Union[bytes, bytearray]) -> int: ...
7073
if sys.version_info >= (3, 5):
71-
def readinto1(self, b: bytearray) -> int: ...
74+
def readinto1(self, b: _bytearray_like) -> int: ...
7275
if sys.version_info >= (3, 4):
7376
def read(self, size: Optional[int] = ...) -> bytes: ...
7477
def read1(self, size: int = ...) -> bytes: ...
@@ -129,10 +132,10 @@ class BytesIO(BinaryIO):
129132
def closed(self) -> bool: ...
130133
# copied from BufferedIOBase
131134
def detach(self) -> RawIOBase: ...
132-
def readinto(self, b: bytearray) -> int: ...
135+
def readinto(self, b: _bytearray_like) -> int: ...
133136
def write(self, b: Union[bytes, bytearray]) -> int: ...
134137
if sys.version_info >= (3, 5):
135-
def readinto1(self, b: bytearray) -> int: ...
138+
def readinto1(self, b: _bytearray_like) -> int: ...
136139
if sys.version_info >= (3, 4):
137140
def read(self, size: Optional[int] = ...) -> bytes: ...
138141
def read1(self, size: int = ...) -> bytes: ...

0 commit comments

Comments
 (0)