Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #985 by accepting both str and bytes as arg for json.loads() #986

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

asdil12
Copy link
Contributor

@asdil12 asdil12 commented Mar 14, 2025

Same as micropython's internal json lib does.

@asdil12 asdil12 force-pushed the decode branch 3 times, most recently from f89aa1c to e53ae58 Compare March 14, 2025 13:06
@@ -413,4 +413,6 @@ def loads(
kw["parse_int"] = parse_int
if parse_constant is not None:
kw["parse_constant"] = parse_constant
if isinstance(s, bytes):
Copy link
Member

Choose a reason for hiding this comment

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

CPython also supports bytearray so this could be:

if isinstance(s, (bytes, bytearray)):

Also, please also update the documentation comment for the loads function to mention that s can be str, bytes or bytearray.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks for the quick response!

Same as micropython's internal json lib does.

Fixes micropython#985.

Signed-off-by: Dominik Heidler <[email protected]>
@dpgeorge dpgeorge merged commit d1a7436 into micropython:master Apr 10, 2025
4 checks passed
@asdil12 asdil12 deleted the decode branch April 10, 2025 12:48
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