Skip to content

Commit 6d85dc3

Browse files
committed
Address review comments: document Any usage and remove tests
1 parent d64fcf4 commit 6d85dc3

2 files changed

Lines changed: 4 additions & 13 deletions

File tree

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from __future__ import annotations
22

3-
from typing import Any
43
from typing_extensions import assert_type
54

6-
from simplejson import JSONDecoder, JSONEncoder, dumps
5+
from simplejson import JSONEncoder, dumps
76

87

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

1615
# Ok:
1716
assert_type(dumps([], cls=CustomEncoder, extra_kw=True), str)
18-
19-
decoder = JSONDecoder()
20-
assert_type(decoder.scan_once("{}", 0), tuple[Any, int])
21-
assert_type(decoder.parse_string('"hello"', 1), tuple[str, int])
22-
assert_type(decoder.parse_array(("[]", 1), decoder.scan_once), tuple[Any, int])
23-
assert_type(
24-
decoder.parse_object(
25-
("{}", 1), decoder.encoding, decoder.strict, decoder.scan_once, decoder.object_hook, decoder.object_pairs_hook
26-
),
27-
tuple[Any, int],
28-
)

‎stubs/simplejson/simplejson/decoder.pyi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ class JSONDecoder:
1313
strict: bool
1414
array_hook: Callable[[list[Any]], Any] | None # transforms a JSON value to an arbitrary value
1515
# They have many parameters, it might be better to use Protocol:
16+
# Any represents the decoded JSON object (dict, or custom value from hook)
1617
parse_object: Callable[..., tuple[Any, int]]
18+
# Any represents the decoded JSON array (list, or custom value from hook)
1719
parse_array: Callable[..., tuple[Any, int]]
1820
parse_string: Callable[..., tuple[str, int]]
1921
memo: dict[Any, Any]
22+
# Any represents the decoded JSON value (str, int, float, bool, list, dict, None)
2023
scan_once: Callable[[str, int], tuple[Any, int]]
2124

2225
def __init__(

0 commit comments

Comments
 (0)