From 3f16982c3c7ee9f47d3519701ba16a8d030e0fde Mon Sep 17 00:00:00 2001 From: huuan26 Date: Sat, 31 Oct 2026 16:46:04 +0700 Subject: [PATCH 1/2] [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/2] [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], )