homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document json "sort_keys" parameter properly
Type: enhancement 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: asvetlov, chris.jerdonek, cvrebert, docs@python, ezio.melotti, godfryd, ncoghlan, petri.lehtinen, python-dev
Priority: normal Keywords: easy, patch

Created on 2012年04月13日 02:42 by ncoghlan, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
json-sort-keys.patch godfryd, 2012年04月30日 18:17
json.rst.patch cvrebert, 2012年09月01日 22:13 b0rk-free docs patch review
json_init.patch cvrebert, 2012年09月01日 22:20 b0rk-free code patch review
issue14570.diff cvrebert, 2012年10月28日 08:15 revised patch review
issue14570-2.7.diff cvrebert, 2012年10月28日 12:43 patch against 2.7 review
Messages (14)
msg158194 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2012年04月13日 02:42
The json "sort_keys" parameter is actually supported as an argument to dump() and dumps() (and is used that way in the examples), but is only documented as an argument to the JSONEncoder constructor.
msg159539 - (view) Author: Michal Nowikowski (godfryd) Date: 2012年04月28日 20:38
In json module there are dump/dumps methods which internally instantiate encoder class JSONEncoder (or some other user-defined encoder clas).
They look as follows:
json.dump(obj, fp, 
 skipkeys=False,
 ensure_ascii=True,
 check_circular=True, 
 allow_nan=True,
 cls=None,
 indent=None,
 separators=None,
 default=None, 
 **kw)
json.JSONEncoder(skipkeys=False, 
 ensure_ascii=True,
 check_circular=True,
 allow_nan=True,
 sort_keys=False,
 indent=None,
 separators=None,
 default=None)
Some of dump/dumps arguments are passed to encoder class:
- skipkeys
- ensure_ascii
- check_circular
- allow_nan
- indent
- separators
- default
And it looks that sort_keys is just missing in keyword args in dump/dumps method.
But it still can be passed implicitly using **kw arg.
I would propose to do:
- add explicitly sort_keys keyword arg to dump/dumps methods
- add passing it to encoder class
- and adjust documentation accordingly.
msg159719 - (view) Author: Michal Nowikowski (godfryd) Date: 2012年04月30日 18:17
Attached a patch.
To preserve current order of arguments in dumps/dump functions sort_keys argument has been added to the end of arguments just before **kw.
msg169189 - (view) Author: Chris Rebert (cvrebert) * Date: 2012年08月27日 07:46
Erm, the patch seems to have some ANSI terminal coloring escape code junk (e.g. "") in it...
msg169671 - (view) Author: Chris Rebert (cvrebert) * Date: 2012年09月01日 22:20
Attached updated patches.
msg170510 - (view) Author: Chris Rebert (cvrebert) * Date: 2012年09月15日 06:09
Any reactions? The patch is pretty straightforward...
msg170522 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012年09月15日 16:35
I would recommend making the added and modified lines not exceed 79 characters in both files. Also, for the .rst file, you can use slashes to break lines as shown in the following example:
http://hg.python.org/cpython/file/09011896374d/Doc/library/argparse.rst#l133 
msg170523 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012年09月15日 16:37
Also, while not strictly necessary, it is more customary and convenient to provide a single patch file for all files.
msg174010 - (view) Author: Chris Rebert (cvrebert) * Date: 2012年10月28日 08:15
Per Chris Jerdonek, here's a combined patch that also makes the docs changes comply with the antiquated line length limit.
msg174034 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年10月28日 12:13
New changeset 40aedc7da30f by Andrew Svetlov in branch '3.2':
Issue #14570: Document json sort_keys parameter properly.
http://hg.python.org/cpython/rev/40aedc7da30f
New changeset 090484ccba7d by Andrew Svetlov in branch '3.3':
Merge issue #14570: Document json sort_keys parameter properly.
http://hg.python.org/cpython/rev/090484ccba7d
New changeset 27ce005372a5 by Andrew Svetlov in branch 'default':
Merge issue #14570: Document json sort_keys parameter properly.
http://hg.python.org/cpython/rev/27ce005372a5 
msg174035 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012年10月28日 12:15
Thanks, Chris!
I have pushed the patch for 3.2-3.4
It cannot be applied to 2.7, please make separate patch for this version.
msg174041 - (view) Author: Chris Rebert (cvrebert) * Date: 2012年10月28日 12:43
Patch for 2.7. This assumes that changing the parameter notation is permissible.
msg174045 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012年10月28日 12:59
New changeset 7784008e9ade by Andrew Svetlov in branch '2.7':
Issue #14570: Document json sort_keys parameter properly.
http://hg.python.org/cpython/rev/7784008e9ade 
msg174046 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012年10月28日 12:59
Fixed, thanks again!
History
Date User Action Args
2022年04月11日 14:57:29adminsetgithub: 58775
2012年10月28日 12:59:51asvetlovsetstatus: open -> closed
resolution: fixed
messages: + msg174046

stage: patch review -> resolved
2012年10月28日 12:59:00python-devsetmessages: + msg174045
2012年10月28日 12:43:23cvrebertsetfiles: + issue14570-2.7.diff

messages: + msg174041
2012年10月28日 12:15:09asvetlovsetnosy: + asvetlov
messages: + msg174035
2012年10月28日 12:13:24python-devsetnosy: + python-dev
messages: + msg174034
2012年10月28日 08:15:53cvrebertsetfiles: + issue14570.diff

messages: + msg174010
2012年09月15日 16:37:35chris.jerdoneksetmessages: + msg170523
2012年09月15日 16:35:10chris.jerdoneksetnosy: + chris.jerdonek
messages: + msg170522
2012年09月15日 06:12:54ezio.melottisetnosy: + petri.lehtinen

stage: needs patch -> patch review
2012年09月15日 06:09:04cvrebertsetmessages: + msg170510
2012年09月01日 22:20:18cvrebertsetfiles: + json_init.patch

messages: + msg169671
2012年09月01日 22:13:31cvrebertsetfiles: + json.rst.patch
2012年08月27日 07:46:29cvrebertsetnosy: + cvrebert
messages: + msg169189
2012年04月30日 18:17:45godfrydsetfiles: + json-sort-keys.patch
keywords: + patch
messages: + msg159719
2012年04月28日 20:38:46godfrydsetnosy: + godfryd
messages: + msg159539
2012年04月13日 06:38:27ezio.melottisetnosy: + ezio.melotti
2012年04月13日 02:42:27ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /