diff --git a/stdlib/_typeshed/__init__.pyi b/stdlib/_typeshed/__init__.pyi index cf67751f863b..d65216079d57 100644 --- a/stdlib/_typeshed/__init__.pyi +++ b/stdlib/_typeshed/__init__.pyi @@ -6,7 +6,7 @@ import array import mmap import sys from os import PathLike -from typing import AbstractSet, Any, Container, Iterable, Protocol, Tuple, TypeVar, Union +from typing import AbstractSet, Any, Container, Dict, Iterable, List, Protocol, Tuple, TypeVar, Union from typing_extensions import Literal, final _KT = TypeVar("_KT") @@ -167,3 +167,7 @@ else: @final class NoneType: def __bool__(self) -> Literal[False]: ... + +JsonObject = Dict[str, Any] # Any is Json +JsonArray = List[Any] # Any is Json +Json = Union[JsonObject, JsonArray, str, float, int, bool, None] diff --git a/stdlib/json/__init__.pyi b/stdlib/json/__init__.pyi index e37e68ca3b99..e48715015477 100644 --- a/stdlib/json/__init__.pyi +++ b/stdlib/json/__init__.pyi @@ -1,5 +1,5 @@ -from _typeshed import SupportsRead -from typing import IO, Any, Callable, Tuple, Type +from _typeshed import Json, SupportsRead +from typing import IO, Any, Callable, Tuple, Type, overload from .decoder import JSONDecodeError as JSONDecodeError, JSONDecoder as JSONDecoder from .encoder import JSONEncoder as JSONEncoder @@ -33,6 +33,19 @@ def dump( sort_keys: bool = ..., **kwds: Any, ) -> None: ... +@overload +def loads( + s: str | bytes, + *, + cls: Type[JSONDecoder] | None = ..., + object_hook: None = ..., + parse_float: None = ..., + parse_int: None = ..., + parse_constant: None = ..., + object_pairs_hook: None = ..., + **kwds: Any, +) -> Json: ... +@overload def loads( s: str | bytes, *, @@ -44,6 +57,19 @@ def loads( object_pairs_hook: Callable[[list[Tuple[Any, Any]]], Any] | None = ..., **kwds: Any, ) -> Any: ... +@overload +def load( + fp: SupportsRead[str | bytes], + *, + cls: Type[JSONDecoder] | None = ..., + object_hook: None = ..., + parse_float: None = ..., + parse_int: None = ..., + parse_constant: None = ..., + object_pairs_hook: None = ..., + **kwds: Any, +) -> Any: ... +@overload def load( fp: SupportsRead[str | bytes], *,