One function
is_numeric_literal in toon-format/toon-python
The author described this change as “fix: improve numeric literal validation (#21)”. It counts as a record because the check below fails on the code as it stood at 6b26984a0 and passes on 728120d9b, with nothing else changed between the two runs.
Projecttoon-format/toon-python
Fix saved2026-03-17
Sharing licenceMIT · LICENSE
Change size+9 −1
What the code was meant to do, written into the code itself as a docstring
Check if a token represents a valid numeric literal. Rejects numbers with leading zeros (except `"0"` itself or decimals like `"0.5"`). Per Section 7.3 of the TOON specification. Args: token: The token to check Returns: True if the token is a valid numeric literal Examples:
The change
| 19 | 19 | True | |
| 20 | 20 | >>> is_numeric_literal("0123") # Leading zero - not valid | |
| 21 | 21 | False | |
| 22 | + | >>> is_numeric_literal("-01") # Negative with leading zero - not valid | |
| 23 | + | False | |
| 22 | 24 | >>> is_numeric_literal("hello") | |
| 23 | 25 | False | |
| 24 | 26 | """ | |
| 25 | 27 | if not token: | |
| 26 | 28 | return False | |
| 27 | 29 | ||
| 30 | + | # Handle negative numbers | |
| 31 | + | start_idx = 1 if token.startswith("-") else 0 | |
| 32 | + | if start_idx >= len(token): | |
| 33 | + | return False | |
| 34 | + | ||
| 28 | 35 | # Must not have leading zeros (except for `"0"` itself or decimals like `"0.5"`) | |
| 29 | - | if len(token) > 1 and token[0] == "0" and token[1] != ".": | |
| 36 | + | # Check the first digit after optional minus sign | |
| 37 | + | if len(token) > start_idx + 1 and token[start_idx] == "0" and token[start_idx + 1] != ".": | |
| 30 | 38 | return False | |
| 31 | 39 | ||
| 32 | 40 | # Check if it's a valid number |
The check that tells the two apart
fail→pass·tests/test_numeric_detection.py::TestNumericLiteral::test_leading_zeros_rejected
Check file tests/test_numeric_detection.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it6b26984a01279defdcf40ab9d09bc418fe8133ac
Broken version dated2025-12-02
Moduletoon_format._literal_utils
Units changedis_numeric_literal
Fingerprint4e2b2287ef293401
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.