Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document json "sort_keys" parameter properly #58775

Closed
ncoghlan opened this issue Apr 13, 2012 · 14 comments
Closed

Document json "sort_keys" parameter properly #58775

ncoghlan opened this issue Apr 13, 2012 · 14 comments
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@ncoghlan
Copy link
Contributor

BPO 14570
Nosy @ncoghlan, @ezio-melotti, @asvetlov, @cjerdonek, @akheron
Files
  • json-sort-keys.patch
  • json.rst.patch: b0rk-free docs patch
  • json_init.patch: b0rk-free code patch
  • issue14570.diff: revised patch
  • issue14570-2.7.diff: patch against 2.7
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2012-10-28.12:59:51.783>
    created_at = <Date 2012-04-13.02:42:27.091>
    labels = ['easy', 'type-feature', 'docs']
    title = 'Document json "sort_keys" parameter properly'
    updated_at = <Date 2012-10-28.12:59:51.782>
    user = 'https://github.com/ncoghlan'

    bugs.python.org fields:

    activity = <Date 2012-10-28.12:59:51.782>
    actor = 'asvetlov'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2012-10-28.12:59:51.783>
    closer = 'asvetlov'
    components = ['Documentation']
    creation = <Date 2012-04-13.02:42:27.091>
    creator = 'ncoghlan'
    dependencies = []
    files = ['25427', '27090', '27091', '27759', '27765']
    hgrepos = []
    issue_num = 14570
    keywords = ['patch', 'easy']
    message_count = 14.0
    messages = ['158194', '159539', '159719', '169189', '169671', '170510', '170522', '170523', '174010', '174034', '174035', '174041', '174045', '174046']
    nosy_count = 9.0
    nosy_names = ['ncoghlan', 'ezio.melotti', 'cvrebert', 'asvetlov', 'chris.jerdonek', 'docs@python', 'godfryd', 'python-dev', 'petri.lehtinen']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14570'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @ncoghlan
    Copy link
    Contributor Author

    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.

    @ncoghlan ncoghlan added docs Documentation in the Doc dir easy type-feature A feature request or enhancement labels Apr 13, 2012
    @godfryd
    Copy link
    Mannequin

    godfryd mannequin commented Apr 28, 2012

    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.

    @godfryd
    Copy link
    Mannequin

    godfryd mannequin commented Apr 30, 2012

    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.

    @cvrebert
    Copy link
    Mannequin

    cvrebert mannequin commented Aug 27, 2012

    Erm, the patch seems to have some ANSI terminal coloring escape code junk (e.g. "�[0;31m") in it...

    @cvrebert
    Copy link
    Mannequin

    cvrebert mannequin commented Sep 1, 2012

    Attached updated patches.

    @cvrebert
    Copy link
    Mannequin

    cvrebert mannequin commented Sep 15, 2012

    Any reactions? The patch is pretty straightforward...

    @cjerdonek
    Copy link
    Member

    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

    @cjerdonek
    Copy link
    Member

    Also, while not strictly necessary, it is more customary and convenient to provide a single patch file for all files.

    @cvrebert
    Copy link
    Mannequin

    cvrebert mannequin commented Oct 28, 2012

    Per Chris Jerdonek, here's a combined patch that also makes the docs changes comply with the antiquated line length limit.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 28, 2012

    New changeset 40aedc7da30f by Andrew Svetlov in branch '3.2':
    Issue bpo-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 bpo-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 bpo-14570: Document json sort_keys parameter properly.
    http://hg.python.org/cpython/rev/27ce005372a5

    @asvetlov
    Copy link
    Contributor

    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.

    @cvrebert
    Copy link
    Mannequin

    cvrebert mannequin commented Oct 28, 2012

    Patch for 2.7. This assumes that changing the parameter notation is permissible.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 28, 2012

    New changeset 7784008e9ade by Andrew Svetlov in branch '2.7':
    Issue bpo-14570: Document json sort_keys parameter properly.
    http://hg.python.org/cpython/rev/7784008e9ade

    @asvetlov
    Copy link
    Contributor

    Fixed, thanks again!

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants