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

gh-132021: Add bool type to the list of types that were allowed in keys of encode(...) method #132048

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

srinivasreddy
Copy link
Contributor

@srinivasreddy srinivasreddy commented Apr 3, 2025

@brianschubert
Copy link
Contributor

Hi! This updates the docstring for JSONEncoder.__init__ (i.e. what's shown by help(json.JSONEncoder)). Technically gh-132021 is about this passage from the docs, not the docstring, but it doesn't hurt to clarify the docstring as well. Can you make a similar change to the docs passage in Doc/library/json.rst?

@@ -108,7 +108,7 @@ def __init__(self, *, skipkeys=False, ensure_ascii=True,
"""Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt
encoding of keys that are not str, int, float or None. If
encoding of keys that are not bool, str, int, float or None. If
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: json.dumps uses the order "str, int, float, bool, None" in its docstring and docs, so we might as well use the same order here for consistency

@@ -486,8 +486,8 @@ Encoders and Decoders
(to raise :exc:`TypeError`).

If *skipkeys* is false (the default), a :exc:`TypeError` will be raised when
trying to encode keys that are not :class:`str`, :class:`int`, :class:`float`
or ``None``. If *skipkeys* is true, such items are simply skipped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the spacing, the change is unrelated and it is consistent with the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 1b782e3

Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants