diff --git a/stdlib/2/json.pyi b/stdlib/2/json.pyi index 9cc151b27f34..930d2de7a4d7 100644 --- a/stdlib/2/json.pyi +++ b/stdlib/2/json.pyi @@ -1,10 +1,13 @@ from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Text, Protocol +# documentation for return type: https://docs.python.org/3.7/library/json.html#json-to-py-table +_LoadsReturnType = Union[Dict[Any,Any], List[Any], str, int, float, None] + class JSONDecodeError(ValueError): def dumps(self, obj: Any) -> str: ... def dump(self, obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ... - def loads(self, s: str) -> Any: ... - def load(self, fp: IO[str]) -> Any: ... + def loads(self, s: str) -> _LoadsReturnType: ... + def load(self, fp: IO[str]) -> _LoadsReturnType: ... def dumps(obj: Any, skipkeys: bool = ..., @@ -41,7 +44,7 @@ def loads(s: Union[Text, bytes], parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., - **kwds: Any) -> Any: ... + **kwds: Any) -> _LoadsReturnType: ... class _Reader(Protocol): def read(self) -> Union[Text, bytes]: ... @@ -54,7 +57,7 @@ def load(fp: _Reader, parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., - **kwds: Any) -> Any: ... + **kwds: Any) -> _LoadsReturnType: ... class JSONDecoder(object): def __init__(self, @@ -65,7 +68,7 @@ class JSONDecoder(object): parse_constant: Callable[[str], Any] = ..., strict: bool = ..., object_pairs_hook: Callable[..., Any] = ...) -> None: ... - def decode(self, s: Union[Text, bytes], _w: Any = ...) -> Any: ... + def decode(self, s: Union[Text, bytes], _w: Any = ...) -> _LoadsReturnType: ... def raw_decode(self, s: Union[Text, bytes], idx: int = ...) -> Tuple[Any, Any]: ... class JSONEncoder(object): diff --git a/stdlib/3/json/__init__.pyi b/stdlib/3/json/__init__.pyi index 620b239b46c8..7e1adc016ef8 100644 --- a/stdlib/3/json/__init__.pyi +++ b/stdlib/3/json/__init__.pyi @@ -1,7 +1,7 @@ import sys from typing import Any, IO, Optional, Tuple, Callable, Dict, List, Union, Protocol -from .decoder import JSONDecoder as JSONDecoder +from .decoder import JSONDecoder as JSONDecoder, _LoadsReturnType from .encoder import JSONEncoder as JSONEncoder if sys.version_info >= (3, 5): from .decoder import JSONDecodeError as JSONDecodeError @@ -43,7 +43,7 @@ def loads(s: _LoadsString, parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., - **kwds: Any) -> Any: ... + **kwds: Any) -> _LoadsReturnType: ... class _Reader(Protocol): def read(self) -> _LoadsString: ... @@ -55,4 +55,4 @@ def load(fp: _Reader, parse_int: Optional[Callable[[str], Any]] = ..., parse_constant: Optional[Callable[[str], Any]] = ..., object_pairs_hook: Optional[Callable[[List[Tuple[Any, Any]]], Any]] = ..., - **kwds: Any) -> Any: ... + **kwds: Any) -> _LoadsReturnType: ... diff --git a/stdlib/3/json/decoder.pyi b/stdlib/3/json/decoder.pyi index 8e30c1e73359..e8dca9596edc 100644 --- a/stdlib/3/json/decoder.pyi +++ b/stdlib/3/json/decoder.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, Dict, List, Optional, Tuple +from typing import Any, Callable, Dict, List, Optional, Tuple, Union if sys.version_info >= (3, 5): class JSONDecodeError(ValueError): @@ -10,6 +10,9 @@ if sys.version_info >= (3, 5): colno: int def __init__(self, msg: str, doc: str, pos: int) -> None: ... +# documentation for return type: https://docs.python.org/3.7/library/json.html#json-to-py-table +_LoadsReturnType = Union[Dict[Any,Any], List[Any], str, int, float, None] + class JSONDecoder: object_hook: Callable[[Dict[str, Any]], Any] parse_float: Callable[[str], Any] @@ -24,5 +27,5 @@ class JSONDecoder: parse_constant: Optional[Callable[[str], Any]] = ..., strict: bool = ..., object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], Any]] = ...) -> None: ... - def decode(self, s: str) -> Any: ... + def decode(self, s: str) -> _LoadsReturnType: ... def raw_decode(self, s: str, idx: int = ...) -> Tuple[Any, int]: ...