From 3f16982c3c7ee9f47d3519701ba16a8d030e0fde Mon Sep 17 00:00:00 2001 From: huuan26 Date: Sat, 31 Oct 2026 16:46:04 +0700 Subject: [PATCH 1/3] [simplejson] Replace Incomplete in JSONDecoder and fix scan_once return type --- .../@tests/test_cases/check_simplejson.py | 19 ++++++++++++++++++- stubs/simplejson/simplejson/decoder.pyi | 9 ++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/stubs/simplejson/@tests/test_cases/check_simplejson.py b/stubs/simplejson/@tests/test_cases/check_simplejson.py index c62fd73dad6e..5eebda557499 100644 --- a/stubs/simplejson/@tests/test_cases/check_simplejson.py +++ b/stubs/simplejson/@tests/test_cases/check_simplejson.py @@ -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. @@ -14,3 +15,19 @@ 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], +) diff --git a/stubs/simplejson/simplejson/decoder.pyi b/stubs/simplejson/simplejson/decoder.pyi index 3fc18bc176e5..b45e81919fd3 100644 --- a/stubs/simplejson/simplejson/decoder.pyi +++ b/stubs/simplejson/simplejson/decoder.pyi @@ -1,4 +1,3 @@ -from _typeshed import Incomplete from collections.abc import Callable from re import Match from typing import Any, Literal @@ -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, From d64fcf40412c0f32e9d675d9ff05bf5bd066bf2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 31 Oct 2026 09:48:27 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/simplejson/@tests/test_cases/check_simplejson.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/stubs/simplejson/@tests/test_cases/check_simplejson.py b/stubs/simplejson/@tests/test_cases/check_simplejson.py index 5eebda557499..7b2a6717a96f 100644 --- a/stubs/simplejson/@tests/test_cases/check_simplejson.py +++ b/stubs/simplejson/@tests/test_cases/check_simplejson.py @@ -22,12 +22,7 @@ class CustomEncoder(JSONEncoder): # eventhough it does not have `extra_kw` arg. 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, + ("{}", 1), decoder.encoding, decoder.strict, decoder.scan_once, decoder.object_hook, decoder.object_pairs_hook ), tuple[Any, int], ) From 6d85dc37acd0bdc030a15e45b066dcf4d55fde08 Mon Sep 17 00:00:00 2001 From: huuan26 Date: Tue, 3 Nov 2026 13:30:50 +0700 Subject: [PATCH 3/3] Address review comments: document Any usage and remove tests --- .../@tests/test_cases/check_simplejson.py | 14 +------------- stubs/simplejson/simplejson/decoder.pyi | 3 +++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/stubs/simplejson/@tests/test_cases/check_simplejson.py b/stubs/simplejson/@tests/test_cases/check_simplejson.py index 7b2a6717a96f..c62fd73dad6e 100644 --- a/stubs/simplejson/@tests/test_cases/check_simplejson.py +++ b/stubs/simplejson/@tests/test_cases/check_simplejson.py @@ -1,9 +1,8 @@ from __future__ import annotations -from typing import Any from typing_extensions import assert_type -from simplejson import JSONDecoder, JSONEncoder, dumps +from simplejson import JSONEncoder, dumps 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. # 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], -) diff --git a/stubs/simplejson/simplejson/decoder.pyi b/stubs/simplejson/simplejson/decoder.pyi index b45e81919fd3..752cfc8acfe4 100644 --- a/stubs/simplejson/simplejson/decoder.pyi +++ b/stubs/simplejson/simplejson/decoder.pyi @@ -13,10 +13,13 @@ 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: + # Any represents the decoded JSON object (dict, or custom value from hook) parse_object: Callable[..., tuple[Any, int]] + # Any represents the decoded JSON array (list, or custom value from hook) parse_array: Callable[..., tuple[Any, int]] parse_string: Callable[..., tuple[str, int]] memo: dict[Any, Any] + # Any represents the decoded JSON value (str, int, float, bool, list, dict, None) scan_once: Callable[[str, int], tuple[Any, int]] def __init__(