Mark simplejson as completed (#9211)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Nikita Sobolev
2024-02-18 01:50:46 +03:00
committed by GitHub
parent 522f4bc9bf
commit 3fa6374c9a
7 changed files with 273 additions and 29 deletions

View File

@@ -1,14 +1,13 @@
simplejson.JSONDecodeError.__init__
simplejson.JSONDecoder.__init__
simplejson.JSONDecoder.decode
simplejson.JSONDecoder.raw_decode
simplejson.JSONEncoder.__init__
simplejson.decoder.JSONDecoder.__init__
simplejson.decoder.JSONDecoder.decode
simplejson.decoder.JSONDecoder.raw_decode
simplejson.dump
simplejson.dumps
simplejson.encoder.JSONEncoder.__init__
simplejson.load
simplejson.loads
# Speedups (C vs Python inconsistency):
simplejson.scanner.make_scanner
simplejson.scanner.JSONDecodeError.__init__
simplejson.JSONDecodeError.__init__
# Tests are not included:
simplejson.tests.*
# Internal and compat tools:
simplejson.compat
simplejson.ordered_dict
simplejson.tool
simplejson.OrderedDict

View File

@@ -0,0 +1,16 @@
from __future__ import annotations
from typing_extensions import assert_type
from simplejson import JSONEncoder, dumps
class CustomEncoder(JSONEncoder): # eventhough it does not have `extra_kw` arg.
...
# We are only testing `dumps` here, because they are all the same:
dumps([], extra_kw=True) # type: ignore
# Ok:
assert_type(dumps([], cls=CustomEncoder, extra_kw=True), str)

View File

@@ -1,6 +1,2 @@
version = "3.19.*"
upstream_repository = "https://github.com/simplejson/simplejson"
partial_stub = true
[tool.stubtest]
ignore_missing_stub = true

View File

@@ -1,4 +1,6 @@
from typing import IO, Any
from _typeshed import SupportsRichComparison
from collections.abc import Callable
from typing import IO, Any, TypeVar, overload
from typing_extensions import TypeAlias
from simplejson.decoder import JSONDecoder as JSONDecoder
@@ -7,8 +9,160 @@ from simplejson.raw_json import RawJSON as RawJSON
from simplejson.scanner import JSONDecodeError as JSONDecodeError
_LoadsString: TypeAlias = str | bytes | bytearray
_T = TypeVar("_T")
def dumps(obj: Any, *args: Any, **kwds: Any) -> str: ...
def dump(obj: Any, fp: IO[str], *args: Any, **kwds: Any) -> None: ...
def loads(s: _LoadsString, **kwds: Any) -> Any: ...
def load(fp: IO[str], **kwds: Any) -> Any: ...
@overload
def dumps(
obj: Any,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
*,
cls: type[JSONEncoder],
indent: str | int | None = ...,
separators: tuple[str, str] | None = ...,
encoding: str = ...,
default: Callable[[Any], Any] | None = ...,
use_decimal: bool = ...,
namedtuple_as_object: bool = ...,
tuple_as_array: bool = ...,
bigint_as_string: bool = ...,
sort_keys: bool = ...,
item_sort_key: Callable[[Any], SupportsRichComparison] | None = ...,
for_json: bool = ...,
ignore_nan: bool = ...,
int_as_string_bitcount: int | None = ...,
iterable_as_array: bool = ...,
**kw: Any,
) -> str: ...
@overload
def dumps(
obj: Any,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
cls: type[JSONEncoder] | None = ...,
indent: str | int | None = ...,
separators: tuple[str, str] | None = ...,
encoding: str = ...,
default: Callable[[Any], Any] | None = ...,
use_decimal: bool = ...,
namedtuple_as_object: bool = ...,
tuple_as_array: bool = ...,
bigint_as_string: bool = ...,
sort_keys: bool = ...,
item_sort_key: Callable[[Any], SupportsRichComparison] | None = ...,
for_json: bool = ...,
ignore_nan: bool = ...,
int_as_string_bitcount: int | None = ...,
iterable_as_array: bool = ...,
) -> str: ...
@overload
def dump(
obj: Any,
fp: IO[str],
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
*,
cls: type[JSONEncoder],
indent: str | int | None = ...,
separators: tuple[str, str] | None = ...,
encoding: str = ...,
default: Callable[[Any], Any] | None = ...,
use_decimal: bool = ...,
namedtuple_as_object: bool = ...,
tuple_as_array: bool = ...,
bigint_as_string: bool = ...,
sort_keys: bool = ...,
item_sort_key: Callable[[Any], SupportsRichComparison] | None = ...,
for_json: bool = ...,
ignore_nan: bool = ...,
int_as_string_bitcount: int | None = ...,
iterable_as_array: bool = ...,
**kw: Any,
) -> None: ...
@overload
def dump(
obj: Any,
fp: IO[str],
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
cls: type[JSONEncoder] | None = ...,
indent: str | int | None = ...,
separators: tuple[str, str] | None = ...,
encoding: str = ...,
default: Callable[[Any], Any] | None = ...,
use_decimal: bool = ...,
namedtuple_as_object: bool = ...,
tuple_as_array: bool = ...,
bigint_as_string: bool = ...,
sort_keys: bool = ...,
item_sort_key: Callable[[Any], SupportsRichComparison] | None = ...,
for_json: bool = ...,
ignore_nan: bool = ...,
int_as_string_bitcount: int | None = ...,
iterable_as_array: bool = ...,
) -> None: ...
@overload
def loads(
s: _LoadsString,
encoding: str | None = ...,
*,
cls: type[JSONDecoder],
object_hook: Callable[[dict[Any, Any]], Any] | None = ...,
parse_float: Callable[[str], Any] | None = ...,
parse_int: Callable[[str], Any] | None = ...,
parse_constant: Callable[[str], Any] | None = ...,
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = ...,
use_decimal: bool = ...,
allow_nan: bool = ...,
**kw: Any,
) -> Any: ...
@overload
def loads(
s: _LoadsString,
encoding: str | None = ...,
cls: type[JSONDecoder] | None = ...,
object_hook: Callable[[dict[Any, Any]], Any] | None = ...,
parse_float: Callable[[str], Any] | None = ...,
parse_int: Callable[[str], Any] | None = ...,
parse_constant: Callable[[str], Any] | None = ...,
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = ...,
use_decimal: bool = ...,
allow_nan: bool = ...,
) -> Any: ...
@overload
def load(
fp: IO[str],
encoding: str | None = ...,
*,
cls: type[JSONDecoder],
object_hook: Callable[[dict[Any, Any]], Any] | None = ...,
parse_float: Callable[[str], Any] | None = ...,
parse_int: Callable[[str], Any] | None = ...,
parse_constant: Callable[[str], Any] | None = ...,
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = ...,
use_decimal: bool = ...,
allow_nan: bool = ...,
**kw: Any,
) -> Any: ...
@overload
def load(
fp: IO[str],
encoding: str | None = ...,
cls: type[JSONDecoder] | None = ...,
object_hook: Callable[[dict[Any, Any]], Any] | None = ...,
parse_float: Callable[[str], Any] | None = ...,
parse_int: Callable[[str], Any] | None = ...,
parse_constant: Callable[[str], Any] | None = ...,
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = ...,
use_decimal: bool = ...,
allow_nan: bool = ...,
) -> Any: ...
def simple_first(kv: tuple[_T, object]) -> tuple[bool, _T]: ...

View File

@@ -1,7 +1,30 @@
from collections.abc import Callable
from re import Match
from typing import Any
from typing import Any, Literal
class JSONDecoder:
def __init__(self, **kwargs: Any) -> None: ...
def decode(self, s: str, _w: Match[str], _PY3: bool) -> Any: ...
def raw_decode(self, s: str, idx: int, _w: Match[str], _PY3: bool) -> tuple[Any, int]: ...
encoding: str
object_hook: Callable[[dict[Any, Any]], Any] | None
parse_float: Callable[[str], Any] | None
parse_int: Callable[[str], Any] | None
parse_constant: Callable[[str], Any] | None
strict: bool
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None
memo: dict[Any, Any]
scan_once: Callable[[str, int], tuple[bool, int]]
def __init__(
self,
encoding: str | None = ...,
object_hook: Callable[[dict[Any, Any]], Any] | None = ...,
parse_float: Callable[[str], Any] | None = ...,
parse_int: Callable[[str], Any] | None = ...,
parse_constant: Callable[[str], Any] | None = ...,
strict: bool = ...,
object_pairs_hook: Callable[[list[tuple[Any, Any]]], Any] | None = ...,
allow_nan: bool = ...,
) -> None: ...
def decode(self, s: str, _w: Callable[[str, int], Match[str]] = ..., _PY3: Literal[True] = ...) -> Any: ...
def raw_decode(
self, s: str, idx: int = ..., _w: Callable[[str, int], Match[str]] = ..., _PY3: Literal[True] = ...
) -> tuple[Any, int]: ...

View File

@@ -1,10 +1,60 @@
from collections.abc import Iterator
from typing import Any, NoReturn
import re
from _typeshed import SupportsRichComparison
from collections.abc import Callable, Iterator
from typing import Any, Literal, NoReturn
ESCAPE: re.Pattern[str]
ESCAPE_ASCII: re.Pattern[str]
HAS_UTF8: re.Pattern[str]
ESCAPE_DCT: dict[str, str]
FLOAT_REPR: Callable[[object], str]
class JSONEncoder:
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
item_separator: str
key_separator: str
skipkeys: bool
ensure_ascii: bool
check_circular: bool
allow_nan: bool
sort_keys: bool
indent: str
encoding: str
use_decimal: bool
namedtuple_as_object: bool
tuple_as_array: bool
bigint_as_string: bool
item_sort_key: Callable[[Any], SupportsRichComparison] | None
for_json: bool
ignore_nan: bool
int_as_string_bitcount: int | None
iterable_as_array: bool
def __init__(
self,
skipkeys: bool = ...,
ensure_ascii: bool = ...,
check_circular: bool = ...,
allow_nan: bool = ...,
sort_keys: bool = ...,
indent: str | int | None = ...,
separators: tuple[str, str] | None = ...,
encoding: str = ...,
default: Callable[[Any], Any] | None = ...,
use_decimal: bool = ...,
namedtuple_as_object: bool = ...,
tuple_as_array: bool = ...,
bigint_as_string: bool = ...,
item_sort_key: Callable[[Any], SupportsRichComparison] | None = ...,
for_json: bool = ...,
ignore_nan: bool = ...,
int_as_string_bitcount: int | None = ...,
iterable_as_array: bool = ...,
) -> None: ...
def encode(self, o: Any) -> str: ...
def default(self, o: Any) -> NoReturn: ...
def iterencode(self, o: Any) -> Iterator[str]: ...
class JSONEncoderForHTML(JSONEncoder): ...
def encode_basestring(s: str | bytes, _PY3: Literal[True] = ..., _q: str = ...) -> str: ...
def py_encode_basestring_ascii(s: str | bytes, _PY3: Literal[True] = ...) -> str: ...

View File

@@ -1,3 +1,7 @@
from collections.abc import Callable
from simplejson.decoder import JSONDecoder
class JSONDecodeError(ValueError):
msg: str
doc: str
@@ -7,3 +11,5 @@ class JSONDecodeError(ValueError):
colno: int
endlineno: int | None
endcolno: int | None
def make_scanner(context: JSONDecoder) -> Callable[[str, int], tuple[bool, int]]: ...