Skip to content

[simplejson] Replace Incomplete in JSONDecoder and fix scan_once return type - #16666

Merged
srittau merged 3 commits into
python:mainfrom
huuan26:fix/simplejson-decoder-types
Nov 3, 2026
Merged

srittau merged 3 commits into
python:mainfrom
huuan26:fix/simplejson-decoder-types

Conversation

@huuan26

@huuan26 huuan26 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR improves type annotations in simplejson.JSONDecoder:

  1. Fix scan_once return type: previously typed as Callable[[str, int], tuple[bool, int]]. At runtime, scan_once parses any JSON value (string, number, array, object, bool, null) and returns tuple[Any, int] representing (parsed_value, end_idx).
  2. Replace Incomplete with concrete types:
    • parse_string: returns tuple[str, int].
    • parse_object and parse_array: return tuple[Any, int].
  3. Remove unused from _typeshed import Incomplete.
  4. Add assert_type tests covering JSONDecoder methods in stubs/simplejson/@tests/test_cases/check_simplejson.py.

Verification

  • flake8 stubs/simplejson: passed (0 errors)
  • python tests/regr_test.py simplejson: passed with mypy
  • python tests/stubtest_third_party.py simplejson: passed (success against installed simplejson)
  • python tests/check_typeshed_structure.py: passed

@github-actions

This comment has been minimized.

("{}", 1), decoder.encoding, decoder.strict, decoder.scan_once, decoder.object_hook, decoder.object_pairs_hook
),
tuple[Any, int],
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the tests. In typeshed, we only add regression tests for functions and classes which are known to have caused complex problems in the past, or where stubs are difficult to get right. 100% test coverage for typeshed is neither necessary nor desirable, as it would lead to code duplication.

See tests/REGRESSION.md for more information.

Comment on lines +16 to +20
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]]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need unobvious Anys to be documented (using comments). Please add a comment what Any means here.

@huuan26

huuan26 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review! I have removed the extra tests and added comments explaining what Any represents in parse_object, parse_array, and scan_once.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
srittau merged commit 76c42f0 into python:main Nov 3, 2026
136 of 137 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants