Repository navigation
[simplejson] Replace Incomplete in JSONDecoder and fix scan_once return type - #16666
Conversation
This comment has been minimized.
This comment has been minimized.
| ("{}", 1), decoder.encoding, decoder.strict, decoder.scan_once, decoder.object_hook, decoder.object_pairs_hook | ||
| ), | ||
| tuple[Any, int], | ||
| ) |
There was a problem hiding this comment.
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.
| 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]] |
There was a problem hiding this comment.
We need unobvious Anys to be documented (using comments). Please add a comment what Any means here.
|
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. |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Summary
This PR improves type annotations in
simplejson.JSONDecoder:scan_oncereturn type: previously typed asCallable[[str, int], tuple[bool, int]]. At runtime,scan_onceparses any JSON value (string, number, array, object, bool, null) and returnstuple[Any, int]representing(parsed_value, end_idx).Incompletewith concrete types:parse_string: returnstuple[str, int].parse_objectandparse_array: returntuple[Any, int].from _typeshed import Incomplete.assert_typetests coveringJSONDecodermethods instubs/simplejson/@tests/test_cases/check_simplejson.py.Verification
flake8 stubs/simplejson: passed (0 errors)python tests/regr_test.py simplejson: passed with mypypython tests/stubtest_third_party.py simplejson: passed (success against installed simplejson)python tests/check_typeshed_structure.py: passed