Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion stubs/simplejson/@tests/test_cases/check_simplejson.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import Any
from typing_extensions import assert_type

from simplejson import JSONEncoder, dumps
from simplejson import JSONDecoder, JSONEncoder, dumps


class CustomEncoder(JSONEncoder): # eventhough it does not have `extra_kw` arg.
Expand All @@ -14,3 +15,14 @@ class CustomEncoder(JSONEncoder): # eventhough it does not have `extra_kw` arg.

# Ok:
assert_type(dumps([], cls=CustomEncoder, extra_kw=True), str)

decoder = JSONDecoder()
assert_type(decoder.scan_once("{}", 0), tuple[Any, int])
assert_type(decoder.parse_string('"hello"', 1), tuple[str, int])
assert_type(decoder.parse_array(("[]", 1), decoder.scan_once), tuple[Any, int])
assert_type(
decoder.parse_object(
("{}", 1), decoder.encoding, decoder.strict, decoder.scan_once, decoder.object_hook, decoder.object_pairs_hook
),
tuple[Any, int],
)
9 changes: 4 additions & 5 deletions stubs/simplejson/simplejson/decoder.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import Incomplete
from collections.abc import Callable
from re import Match
from typing import Any, Literal
Expand All @@ -14,11 +13,11 @@ class JSONDecoder:
strict: bool
array_hook: Callable[[list[Any]], Any] | None # transforms a JSON value to an arbitrary value
# They have many parameters, it might be better to use Protocol:
parse_object: Callable[..., tuple[Incomplete, int]]
parse_array: Callable[..., tuple[Incomplete, int]]
parse_string: Callable[..., tuple[Incomplete, int]]
parse_object: Callable[..., tuple[Any, int]]
parse_array: Callable[..., tuple[Any, int]]
parse_string: Callable[..., tuple[str, int]]
memo: dict[Any, Any]
scan_once: Callable[[str, int], tuple[bool, int]]
scan_once: Callable[[str, int], tuple[Any, int]]

def __init__(
self,
Expand Down
Loading