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
This commit is contained in:
rchen152
2018-01-04 16:14:38 -08:00
committed by Matthias Kramm
parent fb2c7b34e2
commit f6b60cb3ea
3 changed files with 13 additions and 8 deletions

View File

@@ -1,6 +1,9 @@
from typing import Any, AnyStr, BinaryIO, IO, Text, TextIO, Iterable, Iterator, List, Optional, Type, Tuple, TypeVar, Union
from mmap import mmap
from types import TracebackType
_bytearray_like = Union[bytearray, mmap]
DEFAULT_BUFFER_SIZE = ... # type: int
class BlockingIOError(IOError):
@@ -41,7 +44,7 @@ class _IOBase(BinaryIO):
class _BufferedIOBase(_IOBase):
def read1(self, n: int) -> bytes: ...
def read(self, size: int = ...) -> bytes: ...
def readinto(self, buffer: bytearray) -> int: ...
def readinto(self, buffer: _bytearray_like) -> int: ...
def write(self, s: bytes) -> int: ...
def detach(self) -> _IOBase: ...
@@ -92,8 +95,8 @@ class _RawIOBase(_IOBase):
class FileIO(_RawIOBase, BytesIO): # type: ignore # for __enter__
mode = ... # type: str
closefd = ... # type: bool
def __init__(self, file: str, mode: str = ..., closefd: bool = ...) -> None: ...
def readinto(self, buffer: bytearray)-> int: ...
def __init__(self, file: Union[str, int], mode: str = ..., closefd: bool = ...) -> None: ...
def readinto(self, buffer: _bytearray_like)-> int: ...
def write(self, pbuf: str) -> int: ...
class IncrementalNewlineDecoder(object):

View File

@@ -89,7 +89,6 @@ if sys.version_info >= (3, 5):
def __init__(self, sock: socket, debuglevel: int = ...,
method: Optional[str] = ..., url: Optional[str] = ...) -> None: ...
def read(self, amt: Optional[int] = ...) -> bytes: ...
def readinto(self, b: bytearray) -> int: ...
@overload
def getheader(self, name: str) -> Optional[str]: ...
@overload

View File

@@ -3,10 +3,13 @@ from typing import (
)
import builtins
import codecs
from mmap import mmap
import sys
from types import TracebackType
from typing import TypeVar
_bytearray_like = Union[bytearray, mmap]
DEFAULT_BUFFER_SIZE = ... # type: int
SEEK_SET = ... # type: int
@@ -65,10 +68,10 @@ class RawIOBase(IOBase):
class BufferedIOBase(IOBase):
def detach(self) -> RawIOBase: ...
def readinto(self, b: bytearray) -> int: ...
def readinto(self, b: _bytearray_like) -> int: ...
def write(self, b: Union[bytes, bytearray]) -> int: ...
if sys.version_info >= (3, 5):
def readinto1(self, b: bytearray) -> int: ...
def readinto1(self, b: _bytearray_like) -> int: ...
if sys.version_info >= (3, 4):
def read(self, size: Optional[int] = ...) -> bytes: ...
def read1(self, size: int = ...) -> bytes: ...
@@ -129,10 +132,10 @@ class BytesIO(BinaryIO):
def closed(self) -> bool: ...
# copied from BufferedIOBase
def detach(self) -> RawIOBase: ...
def readinto(self, b: bytearray) -> int: ...
def readinto(self, b: _bytearray_like) -> int: ...
def write(self, b: Union[bytes, bytearray]) -> int: ...
if sys.version_info >= (3, 5):
def readinto1(self, b: bytearray) -> int: ...
def readinto1(self, b: _bytearray_like) -> int: ...
if sys.version_info >= (3, 4):
def read(self, size: Optional[int] = ...) -> bytes: ...
def read1(self, size: int = ...) -> bytes: ...