Skip to content

Accept uppercase E exponent after a leading-zero mantissa - #586

Open
eeshsaxena wants to merge 1 commit into
python-poetry:masterfrom
eeshsaxena:fix/uppercase-exponent-leading-zero
Open

Accept uppercase E exponent after a leading-zero mantissa#586
eeshsaxena wants to merge 1 commit into
python-poetry:masterfrom
eeshsaxena:fix/uppercase-exponent-leading-zero

Conversation

@eeshsaxena

Copy link
Copy Markdown

tomlkit rejects the float 0E2, which is valid TOML. Both e and E are allowed exponent markers, and tomlkit already parses the lowercase form:

import tomlkit

tomlkit.parse("x = 0e2")   # ok, 0.0
tomlkit.parse("x = 0E2")   # tomlkit.exceptions.InvalidNumberError

The signed forms (+0E2, -0E2, 0E+2) fail the same way, and tomllib from the standard library accepts all of them. The valid/float/exponent-upper.toml case in the toml-test suite trips over this on its +0E2 line.

The cause is the "no leading zeros" guard in _parse_number: a mantissa beginning with 0 is exempted only when it is followed by ., o, x, b, or a lowercase e, so 0E... falls through to the leading-zero rejection. Adding 0E to the exempted prefixes fixes it. I covered the plain and signed forms in test_parser.py.

A float like `0E2` is valid TOML, since both `e` and `E` are allowed
exponent markers. The "no leading zeros" guard exempted the mantissa only
for lowercase `0e`, so `0E2` (and `0E+2`, `+0E2`, etc.) were rejected as an
invalid number while `0e2` parsed fine. Add `0E` to the exempted prefixes.
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.

1 participant