Skip to content

Use the first-key error message in the C scanner - #388

Merged
etrepum merged 1 commit into
simplejson:mainfrom
youdie006:first-key-error-message
Sep 13, 2026
Merged

etrepum merged 1 commit into
simplejson:mainfrom
youdie006:first-key-error-message

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

At the first key position a } is still legal, so the message should say so — and the pure Python decoder does (decoder.py:176 vs :236). The C scanner uses the after-a-comma wording there:

simplejson.loads('{unquoted_key: 1}')
# C speedups : Expecting property name enclosed in double quotes
# pure Python: Expecting property name enclosed in double quotes or '}'

_speedups_scan.h:213 raises ERR_OBJECT_PROPERTY unconditionally for both the first key and the post-comma key. The closing-brace check 84 lines below it (_speedups_scan.h:297-301) already makes exactly this distinction with did_parse, and ERR_OBJECT_PROPERTY_FIRST already exists — this reuses both, so '{' was already correct and only the key branch was missing it.

'{unquoted_key: "keys must be quoted"}' is fail3.json from the JSON Checker suite, already vendored in test_fail.py's JSONDOCS; the existing test only asserts that it raises, never the message.

Verification
row result
new test, current main 1 failed
with the fix 1 passed
always ERR_OBJECT_PROPERTY 1 failed
always ERR_OBJECT_PROPERTY_FIRST 1 failed

The last row is why the test has two after-comma cases: '{"spam":42,:1}' and '{"spam":42,unquoted_key: 1}' must keep the plain message at position 11.

The new test passes on the pure Python path against unmodified main, so it encodes the reference behaviour rather than my reading of it.

Full suite with the fix: Ran 460 tests ... OK (skipped=59) — which covers both implementations, since tests/__init__.py:77 wraps the suite in NoExtensionTestSuite. Rebuilt with the debug job's own flags (-Wall -Wextra -Wshadow -Wstrict-prototypes -Werror ...): 0 warnings, 0 errors. The hunk adds no declaration, only an expression, so there is no declaration-after-statement concern for the Python 2.7 wheel job — though I could not test that job locally, as AGENTS.md notes.

Only the message changes; positions and exception types are untouched. decoder.py has emitted the longer string for this input since 2013, and test_fail.py:148 already pins it for '{'.

I left CHANGES.txt alone, since the recent message-parity fixes did too.


Disclosure: I used Claude (an AI assistant) while preparing this change.

At the first key position a '}' is still legal, and the pure Python
decoder says so. The C scanner raised the after-a-comma wording there,
even though the closing-brace check a few lines below already selects
on did_parse.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-11T09:52:35.485585Z cc95047 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@etrepum etrepum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, pending CI verification

@etrepum
etrepum added this pull request to the merge queue Sep 13, 2026
Merged via the queue into simplejson:main with commit 50cadb6 Sep 13, 2026
26 checks passed
etrepum pushed a commit that referenced this pull request Oct 2, 2026
Add CHANGES entries for #387, #388 and #390. Test Python 3.15 and
3.15t via allow-prereleases so the jobs follow 3.15.0 final, add
PyPy 3.12, move debug and TSan builds to CPython 3.14.8, and bump
checkout, setup-python, cache, setup-uv and cibuildwheel.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FpcGq7FDACHqLiW7juM4SK
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 3, 2026
4.2.0 released 2026-10-02

* Start building wheels for Python 3.15 and drop Python 3.8 support
  via upgrade to cibuildwheel v4.2.0
  simplejson/simplejson#385
* Build and test riscv64 Linux wheels on native RISE runners
  simplejson/simplejson#389
* The C scanner now reports the same error message as the pure Python
  decoder for an invalid first key in an object
  simplejson/simplejson#388
* ``int_as_string_bitcount`` now supports thresholds of 64 bits and above
  (including 128-bit integers) in both the C and pure Python encoders;
  the C encoder previously rejected them
  simplejson/simplejson#387
* Circular references introduced through ``for_json()`` or ``_asdict()``
  now raise ``ValueError("Circular reference detected")`` instead of
  recursing without bound
  simplejson/simplejson#390
* CI now tests Python 3.15 (including free-threaded 3.15t), PyPy 3.12,
  CPython 3.14.8 debug builds, and uses current GitHub Actions and
  cibuildwheel v4.2.1
  simplejson/simplejson#386
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 13, 2026
4.2.0 released 2026-10-02

* Start building wheels for Python 3.15 and drop Python 3.8 support
  via upgrade to cibuildwheel v4.2.0
  simplejson/simplejson#385
* Build and test riscv64 Linux wheels on native RISE runners
  simplejson/simplejson#389
* The C scanner now reports the same error message as the pure Python
  decoder for an invalid first key in an object
  simplejson/simplejson#388
* ``int_as_string_bitcount`` now supports thresholds of 64 bits and above
  (including 128-bit integers) in both the C and pure Python encoders;
  the C encoder previously rejected them
  simplejson/simplejson#387
* Circular references introduced through ``for_json()`` or ``_asdict()``
  now raise ``ValueError("Circular reference detected")`` instead of
  recursing without bound
  simplejson/simplejson#390
* CI now tests Python 3.15 (including free-threaded 3.15t), PyPy 3.12,
  CPython 3.14.8 debug builds, and uses current GitHub Actions and
  cibuildwheel v4.2.1
  simplejson/simplejson#386
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Oct 21, 2026
4.2.0 released 2026-10-02

* Start building wheels for Python 3.15 and drop Python 3.8 support
  via upgrade to cibuildwheel v4.2.0
  simplejson/simplejson#385
* Build and test riscv64 Linux wheels on native RISE runners
  simplejson/simplejson#389
* The C scanner now reports the same error message as the pure Python
  decoder for an invalid first key in an object
  simplejson/simplejson#388
* ``int_as_string_bitcount`` now supports thresholds of 64 bits and above
  (including 128-bit integers) in both the C and pure Python encoders;
  the C encoder previously rejected them
  simplejson/simplejson#387
* Circular references introduced through ``for_json()`` or ``_asdict()``
  now raise ``ValueError("Circular reference detected")`` instead of
  recursing without bound
  simplejson/simplejson#390
* CI now tests Python 3.15 (including free-threaded 3.15t), PyPy 3.12,
  CPython 3.14.8 debug builds, and uses current GitHub Actions and
  cibuildwheel v4.2.1
  simplejson/simplejson#386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants