Issue 9296: json module skipkeys handling changed exception types in 2.7 (original) (raw)

Created on 2010-07-18 15:48 by doughellmann, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
json_skipkeys.py doughellmann,2010-07-18 15:57
json_trunk.diff ysj.ray,2010-07-20 04:00 patch against the trunk.
json_py3k.diff ysj.ray,2010-07-20 04:00 patch against py3k
Messages (12)
msg110660 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-18 15:48
Under Python 2.6 the json encoder raised a TypeError when it encountered dictionary keys that were not strings. Under 2.7, that exception has changed to a ValueError, but the documentation still says it raises TypeError. I'm not sure which is right, but TypeError seems like the correct exception.
msg110661 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-18 15:57
The attached file json_skipkeys.py illustrates the problem.
msg110663 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-18 16:14
Looking into the code, I see in _json.c that a ValueError is raised by encoder_listencode_dict() on line 2150, but in the pure-Python implementation in json/encoder.py a TypeError is raised by _make_iterencode() on line 376.
msg110749 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-07-19 13:38
Adding some people to nosy: Bob, who wrote the code, and Antoine and Benjamin who were involved in the update and probably have an opinion on the correct fix. (c.f.: Issue4136)
msg110754 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-19 13:50
TypeError sounds right indeed. Patches welcome (even better with tests).
msg110756 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-19 13:55
Bob fixed this in simplejson under ticket 82 (http://code.google.com/p/simplejson/issues/detail?id=82).
msg110861 - (view) Author: ysj.ray (ysj.ray) Date: 2010-07-20 04:00
I worked out two patches, one for trunk and one for py3k, both with tests, hope someone could do a reviewing.
msg110884 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-20 11:04
A quick look suggests that the patches are ok, thank you.
msg110946 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-20 18:50
Ray, thanks for the patches. Antoine, I appreciate the review. I'll try to get these checked in to svn in the next day or two. I see that this ticket is tagged as related to versions 2.7, 3.1, and 3.2. Should the changes be applied to any branches other than trunk and py3k?
msg110952 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-07-20 19:05
> Should the changes be applied to any branches other than trunk and py3k? release31-maint.
msg110972 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-07-20 20:54
I believe there are no commits on trunk. Affected branches are py3k and release{27,31}-maint IIUC.
msg111042 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2010-07-21 12:36
Committed to py3k as r83016, release31-maint as r83017, and release27-maint as r83018. Thanks for your help, everyone.
History
Date User Action Args
2022-04-11 14:57:03 admin set github: 53542
2010-07-21 12:36:54 doughellmann set status: open -> closedresolution: fixedmessages: +
2010-07-20 20:54:02 eric.araujo set nosy: + eric.araujomessages: +
2010-07-20 19:05:40 pitrou set messages: +
2010-07-20 18:50:59 doughellmann set messages: +
2010-07-20 11:04:00 pitrou set messages: + stage: needs patch -> commit review
2010-07-20 04:00:41 ysj.ray set files: + json_py3k.diff
2010-07-20 04:00:11 ysj.ray set files: + json_trunk.diffnosy: + ysj.raymessages: + keywords: + patch
2010-07-19 13:55:41 doughellmann set messages: +
2010-07-19 13:50:31 pitrou set stage: test needed -> needs patchmessages: + versions: + Python 3.1, Python 3.2
2010-07-19 13:38:34 r.david.murray set nosy: + r.david.murray, pitrou, bob.ippolito, benjamin.petersonmessages: + stage: test needed
2010-07-18 16:14:17 doughellmann set messages: +
2010-07-18 15:57:09 doughellmann set files: + json_skipkeys.pymessages: +
2010-07-18 15:48:55 doughellmann create