Skip to content

Normalize permitted Decimal NaNs before encoding - #255

Merged
lelit merged 1 commit into
python-rapidjson:masterfrom
rupayon123:fix/normalize-decimal-nan-tokens-20261031
Oct 31, 2026
Merged

lelit merged 1 commit into
python-rapidjson:masterfrom
rupayon123:fix/normalize-decimal-nan-tokens-20261031

Conversation

@rupayon123

Copy link
Copy Markdown
Contributor

With NM_DECIMAL | NM_NAN, Decimal values such as sNaN, -NaN and NaN123 are written using their Python spelling. Several of those tokens cannot be read back by rapidjson.loads.

Recognize Decimal NaNs and emit the existing canonical NaN token when NM_NAN is enabled. Strict mode still rejects nonfinite values; finite decimals and signed infinities keep their current encoding. The new path retains the encoder's Python error check, including exceptions from actual stream writes.

Validation on native macOS arm64 / CPython 3.13.14:

  • Rebuilt and installed the cp313 wheel: 1,236 tests passed, 17 existing debug-only skips and two existing xfails.
  • Stubtest passed for the module. All 24 canonical NaN roundtrips passed, with 24 finite/Infinity and eight reference-count controls retained.
  • Twenty closed StringIO cases preserve the original write exception; independent stream probes also passed.
  • Required documentation tests still have one failure out of 274 on both pristine and patched builds: the existing NM_NATIVE large-integer precision example expects 1.2345678901234566e+29 and produces 1.2345678901234568e+29. No doctest expectations or skips were changed.

Canonical encoding does not preserve a NaN's sign, payload or signaling identity. Debug-Python and the supported hosted runtime/platform matrix remain unrun locally.

@lelit
lelit merged commit a8b1aed into python-rapidjson:master Oct 31, 2026
3 of 10 checks passed
lelit added a commit to lelit/python-rapidjson that referenced this pull request Nov 1, 2026
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