Repository navigation
Quote identifier-shaped numbers (e.g. PDB code 6E72) in JSON output - #445
Open
barlowa124 wants to merge 1 commit into
Open
barlowa124 wants to merge 1 commit into
barlowa124 wants to merge 1 commit into
Conversation
A token like 6E72 is a valid CIF number (6e72) but also a PDB entry ID, and real mmCIF files write _entry.id unquoted. Emitting it bare produced JSON that parses to a float (or Infinity in some readers), changing the value's type. PDB codes such as 6E72 and 7E57 hit this. A new entry in the number-vs-string check quotes values of the form digits + E + digits with no decimal point or sign, alongside the existing 012 exception. Real numeric tokens (1.2E3, 2e4, -3E5, 2E+6) still emit as JSON numbers. Closes project-gemmi#444. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.
Closes #444.
mmJSON (and default CIF-JSON) output wrote
_entry.id 6E72as a bare JSON value, which every JSON parser reads as the float 6e72. Real mmCIF files write such codes unquoted, so the quoting flag cannot disambiguate them.JsonWriter::write_valuenow quotes tokens shaped digits + uppercase E + digits (no decimal point, no sign), next to the existing012exception. This matches the identifier shape of PDB codes (6E72, 7E57) while leaving real numeric tokens alone:1.2E3,2e4,-3E5, and2E+6still emit as JSON numbers.Tested via a new case in
test_cif_json.py(unfixed code produced a float, fixed produces the string) and the full suite passes on Python 3.13 (python -m unittest discoverintests/).