mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 16:14:24 +08:00
Add IO protocols to _typeshed (#4230)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import sys
|
||||
from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Protocol, Type
|
||||
from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Type
|
||||
from _typeshed import SupportsRead
|
||||
|
||||
from .decoder import JSONDecoder as JSONDecoder
|
||||
from .encoder import JSONEncoder as JSONEncoder
|
||||
@@ -33,7 +34,7 @@ def dump(obj: Any,
|
||||
**kwds: Any) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
_LoadsString = Union[str, bytes, bytearray]
|
||||
_LoadsString = Union[str, bytes]
|
||||
else:
|
||||
_LoadsString = str
|
||||
def loads(s: _LoadsString,
|
||||
@@ -46,10 +47,7 @@ def loads(s: _LoadsString,
|
||||
object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ...,
|
||||
**kwds: Any) -> Any: ...
|
||||
|
||||
class _Reader(Protocol):
|
||||
def read(self) -> _LoadsString: ...
|
||||
|
||||
def load(fp: _Reader,
|
||||
def load(fp: SupportsRead[_LoadsString],
|
||||
*,
|
||||
cls: Optional[Type[JSONDecoder]] = ...,
|
||||
object_hook: Optional[Callable[[Dict[Any, Any]], Any]] = ...,
|
||||
|
||||
@@ -4,19 +4,15 @@ import time
|
||||
import gzip
|
||||
import http.client
|
||||
|
||||
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Protocol, Text, Tuple, Type, TypeVar, Union, overload
|
||||
from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Protocol, Text, Tuple, Type, Union, overload
|
||||
from typing_extensions import Literal
|
||||
from types import TracebackType
|
||||
from datetime import datetime
|
||||
from _typeshed import SupportsRead, SupportsWrite
|
||||
|
||||
_T = TypeVar("_T")
|
||||
class _HasTimeTuple(Protocol):
|
||||
class _SupportsTimeTuple(Protocol):
|
||||
def timetuple(self) -> time.struct_time: ...
|
||||
class _HasWrite(Protocol):
|
||||
def write(self, __o: str) -> None: ...
|
||||
class _HasRead(Protocol):
|
||||
def read(self) -> bytes: ...
|
||||
_DateTimeComparable = Union[DateTime, datetime, str, _HasTimeTuple]
|
||||
_DateTimeComparable = Union[DateTime, datetime, str, _SupportsTimeTuple]
|
||||
_Marshallable = Union[None, bool, int, float, str, bytes, tuple, list, dict, datetime, DateTime, Binary]
|
||||
_XMLDate = Union[int, datetime, Tuple[int, ...], time.struct_time]
|
||||
_HostType = Union[Tuple[str, Dict[str, str]], str]
|
||||
@@ -77,7 +73,7 @@ class DateTime:
|
||||
def make_comparable(self, other: _DateTimeComparable) -> Tuple[str, str]: ... # undocumented
|
||||
def timetuple(self) -> time.struct_time: ... # undocumented
|
||||
def decode(self, data: Any) -> None: ...
|
||||
def encode(self, out: _HasWrite) -> None: ...
|
||||
def encode(self, out: SupportsWrite[str]) -> None: ...
|
||||
|
||||
def _datetime(data: Any) -> DateTime: ... # undocumented
|
||||
def _datetime_type(data: str) -> datetime: ... # undocumented
|
||||
@@ -88,7 +84,7 @@ class Binary:
|
||||
|
||||
def __init__(self, data: Optional[bytes] = ...) -> None: ...
|
||||
def decode(self, data: bytes) -> None: ...
|
||||
def encode(self, out: _HasWrite) -> None: ...
|
||||
def encode(self, out: SupportsWrite[str]) -> None: ...
|
||||
|
||||
def _binary(data: bytes) -> Binary: ... # undocumented
|
||||
|
||||
@@ -204,7 +200,7 @@ class GzipDecodedResponse(gzip.GzipFile): # undocumented
|
||||
|
||||
io: io.BytesIO
|
||||
|
||||
def __init__(self, response: _HasRead) -> None: ...
|
||||
def __init__(self, response: SupportsRead[bytes]) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
class _Method: # undocumented
|
||||
|
||||
Reference in New Issue
Block a user