classification
Title: JSON encode: more informative error
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Mahmoud Lababidi, ezio.melotti, pitrou, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-03-23 14:48 by Mahmoud Lababidi, last changed 2016-04-10 12:48 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
json_encode.patch Mahmoud Lababidi, 2016-03-23 14:51 review
json_encode.patch Mahmoud Lababidi, 2016-04-04 17:22 review
Messages (7)
msg262272 - (view) Author: Mahmoud Lababidi (Mahmoud Lababidi) * Date: 2016-03-23 14:48
The json.dumps()/encode functionality will raise an Error when an object that cannot be json-encoded is encountered. The current Error message only shows the Object itself. I would like to enhance the error message by also providing the Type. This is useful when numpy.int objects are passed in, but not clear that they are numpy objects.
msg262275 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-03-23 15:01
I think it is better to remove the representation of the object at all. It can be too long and less informative that the type of the object.
msg262679 - (view) Author: Mahmoud Lababidi (Mahmoud Lababidi) * Date: 2016-03-30 19:46
Is there a use case where the representation is too long? I think it may be useful to see the representation, but perhaps you are correct.
msg262857 - (view) Author: Mahmoud Lababidi (Mahmoud Lababidi) * Date: 2016-04-04 17:22
Serhiy,

I've attached a patch without the Object representation. Choose whichever you feel is better.
msg263139 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-10 12:46
> Is there a use case where the representation is too long?

For example large bytes, bytearray or set object.
msg263140 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-10 12:47
New changeset cb1ad434f10e by Serhiy Storchaka in branch 'default':
Issue #26623: TypeError message for JSON unserializible object now contains
https://hg.python.org/cpython/rev/cb1ad434f10e
msg263141 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-10 12:48
Thank you for your contribution Mahmoud.
History
Date User Action Args
2017-11-10 19:33:35serhiy.storchakalinkissue31994 superseder
2016-04-10 12:48:02serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg263141

stage: resolved
2016-04-10 12:47:15python-devsetnosy: + python-dev
messages: + msg263140
2016-04-10 12:46:07serhiy.storchakasetmessages: + msg263139
2016-04-10 12:40:32serhiy.storchakasetassignee: serhiy.storchaka
2016-04-04 17:22:30Mahmoud Lababidisetfiles: + json_encode.patch

messages: + msg262857
2016-03-30 19:46:16Mahmoud Lababidisetmessages: + msg262679
2016-03-23 15:01:05serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg262275
2016-03-23 14:54:05SilentGhostsetnosy: + rhettinger, pitrou, ezio.melotti
2016-03-23 14:51:22Mahmoud Lababidisetfiles: + json_encode.patch
keywords: + patch
2016-03-23 14:48:20Mahmoud Lababidicreate