classification
Title: json.loads parse_constant callback not working anymore
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jakob.Simon-Gaarde, docs@python, eric.araujo, ezio.melotti, georg.brandl, hynek, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-04-29 10:34 by Jakob.Simon-Gaarde, last changed 2012-05-16 17:11 by hynek. This issue is now closed.

Files
File name Uploaded Description Edit
test_parse_constant.py Jakob.Simon-Gaarde, 2012-04-29 10:34
json_parse_constant_doc.patch serhiy.storchaka, 2012-04-29 11:33 review
Messages (10)
msg159596 - (view) Author: Jakob Simon-Gaarde (Jakob.Simon-Gaarde) Date: 2012-04-29 10:34
Hi
It seems like the parse_constant keyword parameter for registering a callback function is no longer called in Python 2.7.

http://docs.python.org/library/json.html#json.load

I am using Python 2.7.3 on Ubuntu 12.04

I have created and attached a script that shows the problem.
Output in Python 2.6:
Met an int!
Met a constant!
{u'a': None, u'b': None}

Output in Python 2.7:
Met an int!
{u'a': None, u'b': False}

So parse_int callback still works btw.

Best Regards Jakob Simon-Gaarde
msg159600 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-04-29 11:21
This behavior was changed in changeset f686aced02a3 three year ago. If this change is intentional, then you need edit documentation.
msg159601 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-04-29 11:25
Hi Jakob,

parse_constant has been changed as of d95e5add3ca4 to be called only on "-Infinity, Infinity, NaN":

        ``parse_constant``, if specified, will be called with one of the
        following strings: -Infinity, Infinity, NaN.
        This can be used to raise an exception if invalid JSON numbers
        are encountered.

And indeed, if you change your example to Infinity, it gets called.

That said, neither the 2.7 nor the dev docs reflect that. So it seems like a documentation bug to me.
msg159604 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-04-29 12:51
The original changeset is at [0], and the commit message just says "even more decoder optimizations".  The official website[1] and the RFC[2] don't list any constant, so I guess the definition of what a constant is is not well defined.

[0]: http://code.google.com/p/simplejson/source/detail?spec=svn103&r=103
[1]: http://www.json.org/
[2]: http://tools.ietf.org/html/rfc4627
msg159685 - (view) Author: Jakob Simon-Gaarde (Jakob.Simon-Gaarde) Date: 2012-04-30 09:54
Ok, I accept that at some point it was decided to take away the call to parse_constant hook on "true" and "false" values. But how does it help me to know this, I still need to react on these values?

It seems a little overkill to parse through all parsed values using object_pairs_hook.

Best Regards
Jakob Simon-Gaarde
msg160846 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-05-16 12:25
I'm afraid I have to close this one as rejected. It works as documented and it's unlikely we'll decide to change it back. I'm sorry.
msg160862 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-05-16 13:44
> I'm afraid I have to close this one as rejected. It works as documented and it's unlikely we'll decide to change it back. I'm sorry.

It does not work as documented. The proposed patch fixes the
documentation.
msg160868 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-05-16 14:18
You're right, I was referring to the doc string.
msg160889 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-16 17:10
New changeset 30d16d1e5175 by Hynek Schlawack in branch '2.7':
#14692 Fix json docs to reflect changes in json.load
http://hg.python.org/cpython/rev/30d16d1e5175

New changeset 4f27c4dc34ed by Hynek Schlawack in branch '3.2':
#14692 Fix json docs to reflect changes in json.load
http://hg.python.org/cpython/rev/4f27c4dc34ed

New changeset 0f6a6f59b002 by Hynek Schlawack in branch 'default':
#14692 Fix json docs to reflect changes in json.load
http://hg.python.org/cpython/rev/0f6a6f59b002
msg160890 - (view) Author: Hynek Schlawack (hynek) * (Python committer) Date: 2012-05-16 17:11
Thanks Serhiy!
History
Date User Action Args
2012-05-16 17:11:57hyneksetstatus: open -> closed
resolution: fixed
messages: + msg160890

stage: patch review -> resolved
2012-05-16 17:10:36python-devsetnosy: + python-dev
messages: + msg160889
2012-05-16 14:18:51hyneksetstatus: closed -> open
resolution: rejected -> (no value)
messages: + msg160868

stage: resolved -> patch review
2012-05-16 13:44:04serhiy.storchakasetmessages: + msg160862
2012-05-16 12:25:10hyneksetstatus: open -> closed
resolution: rejected
messages: + msg160846

stage: needs patch -> resolved
2012-05-04 18:06:52terry.reedysettitle: json.joads parse_constant callback not working anymore -> json.loads parse_constant callback not working anymore
2012-04-30 09:54:45Jakob.Simon-Gaardesetmessages: + msg159685
2012-04-29 12:51:24ezio.melottisetnosy: + rhettinger
messages: + msg159604
2012-04-29 11:33:53serhiy.storchakasetfiles: + json_parse_constant_doc.patch
keywords: + patch
2012-04-29 11:25:04hyneksetversions: + Python 3.2, Python 3.3
nosy: + hynek, eric.araujo, georg.brandl, docs@python

messages: + msg159601

assignee: docs@python
components: + Documentation, - Extension Modules
2012-04-29 11:21:26serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg159600
2012-04-29 10:38:49ezio.melottisetnosy: + ezio.melotti

stage: needs patch
2012-04-29 10:34:25Jakob.Simon-Gaardecreate