Repository navigation
Quote identifier-shaped numbers (e.g. PDB code 6E72) in JSON output - #445
barlowa124 wants to merge 2 commits 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>
|
Thanks, this fixes Questions:
For what it's worth, extended ids ( |
Review on project-gemmi#445 showed digits-E-digits tokens of any length quoted genuine numbers like 1E5 and 5E0. The exception now requires four characters with a single E/e, which covers the PDB code space while leaving other exponents numeric, and the check is case-insensitive for lowercase ids. Boundary cases added to the JSON test.
|
Pushed b75edd7 with the narrowed shape. The exception now requires four characters, all digits except a single A tag-aware rule would need |
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/).