Add IO protocols to _typeshed (#4230)

This commit is contained in:
Sebastian Rittau
2020-06-14 20:44:48 +02:00
committed by GitHub
parent ef74bee249
commit 51cf2f51b8
21 changed files with 80 additions and 131 deletions

View File

@@ -1,7 +1,8 @@
from typing import Any, IO, List, Mapping, MutableMapping, Optional, Protocol, Text, Type, Union
from typing import Any, IO, List, Mapping, MutableMapping, Optional, Text, Type, Union
from _typeshed import StrPath
import datetime
import sys
from _typeshed import SupportsWrite
if sys.version_info >= (3, 6):
_PathLike = StrPath
@@ -11,13 +12,10 @@ elif sys.version_info >= (3, 4):
else:
_PathLike = StrPath
class _Writable(Protocol):
def write(self, obj: str) -> Any: ...
class TomlDecodeError(Exception): ...
def load(f: Union[_PathLike, List[Text], IO[str]], _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ...
def loads(s: Text, _dict: Type[MutableMapping[str, Any]] = ...) -> MutableMapping[str, Any]: ...
def dump(o: Mapping[str, Any], f: _Writable) -> str: ...
def dump(o: Mapping[str, Any], f: SupportsWrite[str]) -> str: ...
def dumps(o: Mapping[str, Any]) -> str: ...

View File

@@ -1,14 +1,9 @@
from typing import Any, AnyStr, Generic, Optional, Protocol, Tuple, TypeVar
from typing import AnyStr, Generic, Tuple
from _typeshed import SupportsWrite
from ..middleware.profiler import *
_T = TypeVar("_T")
_T_contra = TypeVar("_T_contra", contravariant=True)
class _Writable(Protocol[_T_contra]):
def write(self, __s: _T_contra) -> Any: ...
class MergeStream(Generic[_T]):
streams: Tuple[_Writable[_T], ...]
def __init__(self, *streams: _Writable[_T]) -> None: ...
def write(self, data: _T) -> None: ...
class MergeStream(Generic[AnyStr]):
streams: Tuple[SupportsWrite[AnyStr], ...]
def __init__(self, *streams: SupportsWrite[AnyStr]) -> None: ...
def write(self, data: AnyStr) -> None: ...

View File

@@ -13,7 +13,6 @@ from typing import (
MutableSet,
NoReturn,
Optional,
Protocol,
Text,
Tuple,
Type,
@@ -21,6 +20,7 @@ from typing import (
Union,
overload,
)
from _typeshed import SupportsWrite
_K = TypeVar("_K")
_V = TypeVar("_V")
@@ -428,9 +428,6 @@ class WWWAuthenticate(UpdateDictMixin, Dict[str, Any]):
qop: Any
stale: Any
class _Writer(Protocol):
def write(self, data: bytes) -> Any: ...
class FileStorage(object):
name: Optional[Text]
stream: IO[bytes]
@@ -453,7 +450,7 @@ class FileStorage(object):
def mimetype(self) -> str: ...
@property
def mimetype_params(self) -> Dict[str, str]: ...
def save(self, dst: Union[Text, _Writer], buffer_size: int = ...): ...
def save(self, dst: Union[Text, SupportsWrite[bytes]], buffer_size: int = ...): ...
def close(self) -> None: ...
def __nonzero__(self) -> bool: ...
def __bool__(self) -> bool: ...

View File

@@ -2,7 +2,7 @@ import sys
from datetime import datetime, timedelta
from typing import (
Dict, Text, Union, Tuple, Any, Optional, Mapping, Iterable, Callable, List, Type,
TypeVar, Protocol, overload, SupportsInt,
TypeVar, overload, SupportsInt,
)
from _typeshed.wsgi import WSGIEnvironment

View File

@@ -1,5 +1,6 @@
import sys
from typing import Any, Iterable, Iterator, List, Mapping, Optional, Protocol, Tuple
from _typeshed import SupportsWrite
from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment
from ..datastructures import Headers
@@ -9,36 +10,33 @@ class HTTPWarning(Warning): ...
def check_string(context: str, obj: object, stacklevel: int = ...) -> None: ...
class _Readable(Protocol):
class _SupportsReadEtc(Protocol):
def read(self, __size: int = ...) -> bytes: ...
def readline(self, __size: int = ...) -> bytes: ...
def __iter__(self) -> Iterator[bytes]: ...
def close(self) -> Any: ...
class InputStream(object):
def __init__(self, stream: _Readable) -> None: ...
def __init__(self, stream: _SupportsReadEtc) -> None: ...
def read(self, __size: int = ...) -> bytes: ...
def readline(self, __size: int = ...) -> bytes: ...
def __iter__(self) -> Iterator[bytes]: ...
def close(self) -> None: ...
class _FullyWritable(Protocol):
class _SupportsWriteEtc(Protocol):
def write(self, __s: str) -> Any: ...
def flush(self) -> Any: ...
def close(self) -> Any: ...
class ErrorStream(object):
def __init__(self, stream: _FullyWritable) -> None: ...
def __init__(self, stream: _SupportsWriteEtc) -> None: ...
def write(self, s: str) -> None: ...
def flush(self) -> None: ...
def writelines(self, seq: Iterable[str]) -> None: ...
def close(self) -> None: ...
class _Writable(Protocol):
def write(self, __s: str) -> Any: ...
class GuardedWrite(object):
def __init__(self, write: _Writable, chunks: List[int]) -> None: ...
def __init__(self, write: SupportsWrite[str], chunks: List[int]) -> None: ...
def __call__(self, s: str) -> None: ...
class GuardedIterator(object):

View File

@@ -1,4 +1,5 @@
from typing import Any, Optional, Protocol, Iterable, Text
from typing import Any, Optional, Iterable, Text
from _typeshed import SupportsRead
from _typeshed.wsgi import WSGIEnvironment, InputStream
from .middleware.dispatcher import DispatcherMiddleware as DispatcherMiddleware
@@ -26,15 +27,12 @@ class ClosingIterator:
def __next__(self): ...
def close(self): ...
class _Readable(Protocol):
def read(self, size: int = ...) -> bytes: ...
def wrap_file(environ: WSGIEnvironment, file: _Readable, buffer_size: int = ...) -> Iterable[bytes]: ...
def wrap_file(environ: WSGIEnvironment, file: SupportsRead[bytes], buffer_size: int = ...) -> Iterable[bytes]: ...
class FileWrapper:
file: _Readable
file: SupportsRead[bytes]
buffer_size: int
def __init__(self, file: _Readable, buffer_size: int = ...) -> None: ...
def __init__(self, file: SupportsRead[bytes], buffer_size: int = ...) -> None: ...
def close(self) -> None: ...
def seekable(self) -> bool: ...
def seek(self, offset: int, whence: int = ...) -> None: ...

View File

@@ -1,13 +1,12 @@
from typing import Any, IO, Mapping, Optional, Sequence, Text, Union
from typing_extensions import Protocol
from _typeshed import SupportsRead
from yaml.constructor import BaseConstructor, Constructor, SafeConstructor
from yaml.representer import BaseRepresenter, Representer, SafeRepresenter
from yaml.resolver import BaseResolver, Resolver
from yaml.serializer import Serializer
class _Readable(Protocol):
def read(self, size: int) -> Union[Text, bytes]: ...
_Readable = SupportsRead[Union[Text, bytes]]
class CParser:
def __init__(self, stream: Union[str, bytes, _Readable]) -> None: ...