Skip to content

bpo-43340: Document possible UnicodeDecodeErrors from json.load()#25173

Closed
rhettinger wants to merge 1 commit into
python:masterfrom
rhettinger:json_decode_error
Closed

bpo-43340: Document possible UnicodeDecodeErrors from json.load()#25173
rhettinger wants to merge 1 commit into
python:masterfrom
rhettinger:json_decode_error

Conversation

@rhettinger

@rhettinger rhettinger commented Apr 4, 2021

Copy link
Copy Markdown
Contributor

Comment thread Doc/library/json.rst

If the data being deserialized is not a valid JSON document, a
:exc:`JSONDecodeError` will be raised.
If the data being deserialized is not correctly encoded, a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It should also be added for loads().

UnicodeDecodeError can only be raised for binary files. loads() for text never raise UnicodeDecodeError, and in case of load() for text file, UnicodeDecodeError and OSError can only be raised by the read() of the text file. There are many details, and without explaining them we will always get complqains about incomplete documentation, but adding all details will make the documentation too overloaded. We usually do not specify all exceptions which can be raised. Is there a good comromize?

Comment thread Doc/library/json.rst
Comment on lines +270 to +272
If the data being deserialized is not correctly encoded, a
:exc:`UnicodeDecodeError` will be raised, and if the decoded file is not a
valid JSON document, a :exc:`JSONDecodeError` will be raised.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something like this?

Suggested change
If the data being deserialized is not correctly encoded, a
:exc:`UnicodeDecodeError` will be raised, and if the decoded file is not a
valid JSON document, a :exc:`JSONDecodeError` will be raised.
If the binary file does not contain UTF-8, UTF-16 or UTF-32 encoded data, a
:exc:`UnicodeDecodeError` will be raised, and if the data is not a
valid JSON document, a :exc:`JSONDecodeError` will be raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review docs Documentation in the Doc dir skip news

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants