Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems in dealing with scientific notation #4

Closed
ziotom78 opened this issue Jan 24, 2019 · 2 comments
Closed

Problems in dealing with scientific notation #4

ziotom78 opened this issue Jan 24, 2019 · 2 comments

Comments

@ziotom78
Copy link

I'm running Miniconda 3.6.7 on a Linux machine. The following program works as expected:

import qtoml

string = qtoml.dumps({'a': 1.0})
print('Encoded TOML: ', string)
qtoml.loads(string)

However, changing the value of a from 1.0 to 1.0e-9 makes qtoml crash:

import qtoml

string = qtoml.dumps({'a': 1.0e-9})
print('Encoded TOML: ', string)
qtoml.loads(string)

The error is the following:

Encoded TOML:  a = 1e-09

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    qtoml.loads(string)
  File "/HOME/miniconda3/lib/python3.6/site-packages/qtoml/decoder.py", line 514, in loads
    (kl, v), p = parse_pair(p)
  File "/HOME/miniconda3/lib/python3.6/site-packages/qtoml/decoder.py", line 428, in parse_pair
    v, p = parse_value(p)
  File "/HOME/miniconda3/lib/python3.6/site-packages/qtoml/decoder.py", line 391, in parse_value
    raise TOMLDecodeError("can't parse type", p)
qtoml.decoder.TOMLDecodeError: can't parse type (line 1, column 4)

This is a clash between the current TOML specification and the way programming languages output numbers in scientific notation (see my bugreport toml-lang/toml#356). qtoml should remove the trailing zero from exponentials.

alethiophile pushed a commit to alethiophile/toml-test that referenced this issue Jan 25, 2019
@alethiophile
Copy link
Owner

Yup, that's a bug.

Got a test case and a tentative fix. Want to exercise it a bit more before committing it, since it's basically a hack.

alethiophile pushed a commit that referenced this issue Jan 25, 2019
@alethiophile
Copy link
Owner

I think this commit should fix it. I'll push a new version in a bit.

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

No branches or pull requests

2 participants