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: Docstring for json.dumps skipkeys parameter is incorrect
Type: Stage: resolved
Components: Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Matthew Havard, ned.deily, python-dev
Priority: normal Keywords:

Created on 2015-06-30 20:16 by Matthew Havard, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg245997 - (view) Author: Matthew Havard (Matthew Havard) Date: 2015-06-30 20:16
The documentation from json.dumps says this about skipkeys:

    If ``skipkeys`` is false then ``dict`` keys that are not basic types
    (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
    instead of raising a ``TypeError``.

However, that contradicts the docstrings for JSONEncoder in the encoder.py file, and json.dump in the same file, __init__.py:

json.dump:
    If ``skipkeys`` is true then ``dict`` keys that are not basic types
    (``str``, ``int``, ``float``, ``bool``, ``None``) will be skipped
    instead of raising a ``TypeError``.

JSONEncoder:
        If skipkeys is false, then it is a TypeError to attempt
        encoding of keys that are not str, int, long, float or None.  If
        skipkeys is True, such items are simply skipped.

So the fix is just that the word "false" to "true".
msg246061 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-07-02 05:00
Can you say where you are seeing this?  The current 2.7 documentation for json reads:

"If skipkeys is True (default: False), then dict keys that are not of a basic type (str, unicode, int, long, float, bool, None) will be skipped instead of raising a TypeError."

https://docs.python.org/2/library/json.html
https://docs.python.org/3/library/json.html
msg246328 - (view) Author: Matthew Havard (Matthew Havard) Date: 2015-07-05 18:29
It's in the actual code in the docstring: https://hg.python.org/cpython/file/6905a7f8c7ac/Lib/json/__init__.py#l187

I'm really new to Mercurial, so I'm not quite sure how to link to the 2.7 version of the Mercurial repo, but here is the link to Lib/json/__init__.py in the 2.7 version on Github:
https://github.com/python/cpython/blob/2.7/Lib/json/__init__.py#L198
msg246329 - (view) Author: Matthew Havard (Matthew Havard) Date: 2015-07-05 18:33
Also, this typo is present in all versions anyway.
msg246331 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-07-05 18:46
New changeset 803520a8db94 by Ned Deily in branch '2.7':
Issue #24540: fix typo in json.dumps docstring
https://hg.python.org/cpython/rev/803520a8db94

New changeset 0deca75537ec by Ned Deily in branch '3.4':
Issue #24540: fix typo in json.dumps docstring
https://hg.python.org/cpython/rev/0deca75537ec

New changeset 038b4f61d9b7 by Ned Deily in branch '3.5':
Issue #24540: merger from 3.4
https://hg.python.org/cpython/rev/038b4f61d9b7

New changeset 55755b2079fb by Ned Deily in branch 'default':
Issue #24540: merger from 3.5
https://hg.python.org/cpython/rev/55755b2079fb
msg246332 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-07-05 18:49
Thanks, I overlooked the docstring.  Now fixed.
msg246333 - (view) Author: Matthew Havard (Matthew Havard) Date: 2015-07-05 19:02
Great!  Glad to be of service.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68728
2015-07-05 19:02:53Matthew Havardsetmessages: + msg246333
2015-07-05 18:49:06ned.deilysetstatus: open -> closed
versions: + Python 3.4, Python 3.5, Python 3.6
title: Documentation about skipkeys parameter for json.dumps is incorrect -> Docstring for json.dumps skipkeys parameter is incorrect
messages: + msg246332

resolution: fixed
stage: resolved
2015-07-05 18:46:39python-devsetnosy: + python-dev
messages: + msg246331
2015-07-05 18:33:26Matthew Havardsetmessages: + msg246329
2015-07-05 18:29:45Matthew Havardsetmessages: + msg246328
2015-07-02 05:00:55ned.deilysetnosy: + ned.deily
messages: + msg246061
2015-06-30 20:16:22Matthew Havardcreate