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

Strings with a number ending in eight or nine are dumped as integers #524

Closed
albertca opened this issue May 13, 2021 · 3 comments
Closed
Labels

Comments

@albertca
Copy link

Here's a small snippet to reproduce the problem:

import yaml

for x in range(0, 12):
    yaml.dump({'a': '%06s' % x})

And here the output:

"a: '000000'\n"
"a: '000001'\n"
"a: '000002'\n"
"a: '000003'\n"
"a: '000004'\n"
"a: '000005'\n"
"a: '000006'\n"
"a: '000007'\n"
'a: 000008\n'
'a: 000009\n'
"a: '000010'\n"
"a: '000011'\n"

For some reason numbers ending in 8 or 9 are dumped as integers, but they should be strings just like the rest of the numbers. Using larger numbers shows that all numbers ending in 8 or 9 are always dumped as integers.

@albertca
Copy link
Author

Although I don't completely understand the reason why it's exported like this I realize that it does not cause any problem in loading again the generated YAML, which loads as string, so I'm closing the issue.

Sorry for the noise.

@perlpunk
Copy link
Member

That looks like the issue was supposed to land in https://github.com/yaml/pyyaml ?

@perlpunk perlpunk transferred this issue from yaml/libyaml May 14, 2021
@perlpunk
Copy link
Member

I transferred the issue to pyyaml.
There are already existing issues here that discuss this. 000008 is not an integer because pyyaml implements YAML 1.1 currently, and scalars starting with a zero are resolved as octal numbers if they only contain 0-7. 8 and 9 are not octal digits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants