Support EDN symbolic values (##Inf/##-Inf/##NaN) so non-finite floats round-trip#96
Merged
bfontaine merged 1 commit intoJun 17, 2026
Conversation
dumps() emitted bare inf/-inf/nan for non-finite floats, which the reader then read back as Symbol objects instead of floats: silent data corruption with no error. ##Inf/##-Inf/##NaN coming from real EDN could not be read at all (the lexer rejected the leading #). Emit and read Clojure's symbolic values ##Inf/##-Inf/##NaN (https://clojure.org/reference/reader#_symbolic_values) via a SYMBOLIC_VALUE lexer token ordered ahead of the other # tokens, a grammar leaf, and a dump branch, so loads(dumps(x)) round-trips inf/-inf/nan.
Collaborator
|
Merged; thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
dumps()silently corrupts non-finite floats.inf,-inf, andnanare emitted as the bare tokensinf/-inf/nan, which the reader then reads back asSymbolobjects rather than floats:So
loads(dumps(x))does not round-trip for non-finite floats (the repo's owncheck_roundtripinvariant), and the canonical EDN representation produced by Clojure (##Inf/##-Inf/##NaN) cannot be read at all.Fix
Support EDN's symbolic values,
##Inf/##-Inf/##NaN, on both paths:edn_lex.py: aSYMBOLIC_VALUEtoken (\#\#(-Inf|Inf|NaN)), defined ahead of the other#token rules so it takes lexer priority. It maps to the matching float.edn_parse.py:SYMBOLIC_VALUEadded to thep_term_leafrule.edn_dump.py: non-finite floats now dump to##Inf/##-Inf/##NaNinstead of bare tokens.Non-finite floats now round-trip, and
##Inf/##-Inf/##NaNfrom real EDN parse correctly. The non-finite check usesmath.isnan/math.isinf(available on Python 2.6+) to stay within the package's stated version support.Tests
Added
test_symbolic_valuestoEdnTest, covering both parse and dump directions plus the existingcheck_roundtriphelper. It fails before the change (EDNDecodeError) and passes after. Full suite: 39 tests pass;flake8 --max-line-length=100clean. Existing#-dispatch syntax (#{...},#_,#inst,#uuid,#:ns{...}) is unaffected.I used an AI assistant to help investigate this under my direction, and I have reviewed and verified the change myself.