GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Inconsistent errors for JSON-encoding NaNs with allow_nan=False · Issue #86018 · python/cpython

Inconsistent errors for JSON-encoding NaNs with allow_nan=False #86018

New issue
Copy link
New issue
Copy link
Closed
Closed
Inconsistent errors for JSON-encoding NaNs with allow_nan=False#86018
Copy link
Labels
3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

earwig
mannequin
opened on Sep 24, 2020
Issue body actions
BPO 41852
Nosy @serhiy-storchaka, @earwig

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 = None
created_at = <Date 2020-09-24.16:44:20.041>
labels = ['type-bug', '3.8', '3.9', '3.10', 'extension-modules', 'library']
title = 'Inconsistent errors for JSON-encoding NaNs with allow_nan=False'
updated_at = <Date 2020-09-24.17:05:07.621>
user = 'https://github.com/earwig'

bugs.python.org fields:

activity = <Date 2020-09-24.17:05:07.621>
actor = 'serhiy.storchaka'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Extension Modules', 'Library (Lib)']
creation = <Date 2020-09-24.16:44:20.041>
creator = 'earwig'
dependencies = []
files = []
hgrepos = []
issue_num = 41852
keywords = []
message_count = 1.0
messages = ['377450']
nosy_count = 2.0
nosy_names = ['serhiy.storchaka', 'earwig']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41852'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

  • PR: gh-86018 Inconsistent errors for JSON-encoding NaNs with allow_nan=False #99172

Activity

  1. earwig commented on Sep 24, 2020

    @earwig
    earwigmannequin
    on Sep 24, 2020
    MannequinAuthor
    More actions

    json.dump vs. json.dumps have inconsistent error messages when encoding NaN with allow_nan=False:

    >>> json.dumps(float('nan'), allow_nan=False)
    ValueError: Out of range float values are not JSON compliant
    >>> json.dump(float('nan'), sys.stdout, allow_nan=False)
    ValueError: Out of range float values are not JSON compliant: nan

    json.dump's error includes the value (which is useful); json.dumps's does not.

    json.dumps uses this C implementation:

    cpython/Modules/_json.c

    Line 1340 in d67de0a

    static PyObject *

    json.dump uses this Python implementation:

    cpython/Lib/json/encoder.py

    Line 223 in d67de0a

    def floatstr(o, allow_nan=self.allow_nan,

    (Separately, is it expected that only one uses the C implementation? This seems it could have unexpected performance implications - without testing, I would've expected json.dump to take the "faster" path since it doesn't need to hold the entire encoded string in memory.)

  2. earwig
    added
    3.8 (EOL)end of lifeend of life
    3.9 (EOL)end of lifeend of life
    3.10 (EOL)end of lifeend of life
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 24, 2020
  3. ezio-melotti
    transferred this issue fromon Apr 10, 2022
  4. serhiy-storchaka
    added this to @serhiy-storchaka's project python-jsonon May 8, 2022
  5. serhiy-storchaka
    added this to JSON issueson May 19, 2022
  6. WillAyd
    added a commit that references this issue on Nov 6, 2022

    pythongh-86018 Inconsistent errors for JSON-encoding NaNs with allow_…

    17901af
  7. nineteendo commented on Jun 30, 2024

    @nineteendo
    nineteendo
    on Jun 30, 2024
    Contributor
    More actions

    This seems to be fixed:

    >>> json.dumps(float('nan'), allow_nan=False)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\wanne\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 238, in dumps
        **kw).encode(obj)
              ^^^^^^^^^^^
      File "C:\Users\wanne\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py", line 200, in encode
        chunks = self.iterencode(o, _one_shot=True)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Users\wanne\AppData\Local\Programs\Python\Python312\Lib\json\encoder.py", line 258, in iterencode
        return _iterencode(o, 0)
               ^^^^^^^^^^^^^^^^^
    ValueError: Out of range float values are not JSON compliant: nan
  8. picnixz commented on Sep 7, 2024

    @picnixz
    picnixz
    on Sep 7, 2024
    Member
    More actions

    It was reported in a separate issue #99925 and resolved by #99926. I think this one was just forgotten. I'll close it as completed, even though it's a duplicate (well technically, the other is a duplicate...)

    Reacted by Nice Zombies
  9. picnixz
    closed this as completedon Sep 7, 2024
  10. github-project-automation
    moved this to Done in JSON issueson Sep 7, 2024
  11. github-project-automation
    moved this to Done in @serhiy-storchaka's project python-jsonon Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of lifeextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • JSON issues
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.