Skip to content

[fix] Preserve leading whitespace when completing JSON - #22

Open
bensynapse wants to merge 1 commit into
promplate:mainfrom
bensynapse:fix-leading-whitespace
Open

bensynapse wants to merge 1 commit into
promplate:mainfrom
bensynapse:fix-leading-whitespace

Conversation

@bensynapse

Copy link
Copy Markdown

I run Live Tennis API.

Leading whitespace changes the slice returned by the slow completion path. For example, loads(' 123') returns 12, and loads(' true') raises JSONDecodeError.

Add the trimmed prefix length to the completion offset before slicing the original input. This preserves the original prefix for complete values and partially completed strings, literals and containers.

The 144 new parametrized cases cover both completion paths and partial-value restrictions. With the original source, 120 tests fail. With this fix, pdm test passes all 154 examples plus the Hypothesis and performance suites on Python 3.8.20 and 3.14.7.

pdm run pyright ./src/ passes on both versions. Black and isort checks pass, and uv build produces the wheel and source distribution after the CI compatibility override.

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e011a32a-acf3-4547-bd04-c873ba95602c
📥 Commits

Reviewing files that changed from the base of the PR and between e0aa5e2 and 14015b2.

📒 Files selected for processing (2)
  • src/partial_json_parser/core/complete.py
  • tests/test_examples.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Summary

_fix now adds the leading-whitespace length to the completion index when slicing the original JSON input. This preserves the original prefix for complete and partially completed values.

New parameterized tests cover leading whitespace across fix and fix_fast, including partial-value restrictions.

Walkthrough

_fix now accounts for leading whitespace when it slices the original JSON input. Tests cover complete and partial JSON with whitespace across fix and fix_fast, including allowed-type restrictions and error cases.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 14015

The whitespace-offset change appears mergeable; the inspected complete and partial input paths preserve the leading prefix, with no concrete regression identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the leading-whitespace offset fix, affected behavior, tests, and validation results.
Title check Passed The title clearly and concisely identifies the main change: preserving leading whitespace during JSON completion.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

1 participant