[issue24641] Log type of unserializable value when raising JSON TypeError

2017-11-25 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2017-11-25 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:


New changeset cfa797c0681b7fef47cf93955fd06b54ddd09a7f by Serhiy Storchaka in 
branch 'master':
bpo-24641: Improved error message for JSON unserializible keys. (#4364)
https://github.com/python/cpython/commit/cfa797c0681b7fef47cf93955fd06b54ddd09a7f


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2017-11-10 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

The idea about including a path to non-serializable object looks interesting 
(and it would be even more useful for pickling), but harder to implement.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2017-11-10 Thread Serhiy Storchaka

Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +4317
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2017-11-10 Thread Serhiy Storchaka

Serhiy Storchaka  added the comment:

This issue was partially fixed in issue26623. The error message for unsupported 
types now is `"Object of type '%s' is not JSON serializable" % 
o.__class__.__name__`.

But this change is not complete. The error message for non-string keys still 
contains the repr of a key. And the example for default() in the module 
docstring contains the repr of an object.

--
assignee:  -> serhiy.storchaka
stage: test needed -> 
versions: +Python 3.7 -Python 2.7, Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2015-07-18 Thread Bob Ippolito

Bob Ippolito added the comment:

This seems like a very reasonable proposal. It would be great if we could also 
include a path in the error message (e.g. `obj[foo][1][bar]`) as well to 
provide enough context to track down the error quickly.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24641
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2015-07-17 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

I think it would be better to change error message to mention the type only. 
Yet one argument is that the repr of affected object can be very large, while 
the type name usually is short enough. repr() even can raise an exception (e.g. 
MemoryError).

--
nosy: +bob.ippolito, pitrou, serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24641
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2015-07-17 Thread Terry J. Reedy

Terry J. Reedy added the comment:

A typical TypeError message use the following pattern:
  TypeError: 'int' object is not callable
as it is the class, not the value, that is the problem.

If the same is always true for the JSON TypeError, at the point of failure, 
then the dumps message could follow the same pattern.

However, I don't know if the message *is* value independent.  The SO question 
asked about

TypeError: {'album': [uRooney's Lost Album], 'title': [u'The Kids
After Sunset'], 'artist': [u'Rooney']} is not JSON serializable

and the OP claimed in a comment to the accepted answer that the problem was 
that the value objects represented as lists were not list() objects, just as 
'5' here is not an int() object.

The JSON error code, in 3.5 at

  File C:\Programs\Python35\lib\json\encoder.py, line 180, in default
raise TypeError(repr(o) +  is not JSON serializable)

could be expanded to check whether the string representation starts with the 
class name and if it does not, add 'classname' object at the front. This 
would solve Madison's posted issue, but not the SO problem.
(It would, however, have made it clear that the {}s represented a real dict() 
object and directed attention inward.)

For testing, compile('','','exec') returns an object that cannot be dumped.

To me, this looks more like an enhancement than bugfix, so a change might be 
limited to future releases.

--
nosy: +ezio.melotti, rhettinger, terry.reedy
stage:  - test needed
type:  - enhancement
versions: +Python 3.5, Python 3.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24641
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24641] Log type of unserializable value when raising JSON TypeError

2015-07-15 Thread Madison May

New submission from Madison May:

Currently the json lib only logs the string representation of the variable, 
which does not always include type information.

I recently ran into a difficult to debug issue with code similar to the 
following:

```
import json
import numpy as np
d = {'data': np.int16(5)}
json.dumps(d)
```

which produces the following error:

```
TypeError: 5 is not JSON serializable
```

It took us quite a while to determine that `5` was actually of type `np.int` 
instead of the native type.

A cursory glance at StackOverflow suggests that I'm not alone in running into 
this issue: 
http://stackoverflow.com/questions/10872604/json-dump-throwing-typeerror-is-not-json-serializable-on-seemingly-vali


I'd like to consider modifying the error message to be more similar to the 
following:

```
TypeError: 5 of type `numpy.int16` is not JSON serializable
```

--
components: Library (Lib)
messages: 246776
nosy: Madison May
priority: normal
severity: normal
status: open
title: Log type of unserializable value when raising JSON TypeError
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24641
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com