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

Inconsistent quoting for strings representing zero-padded numbers ending with 8 or 9. #577

Closed
wflynny opened this issue Oct 18, 2021 · 1 comment

Comments

@wflynny
Copy link

wflynny commented Oct 18, 2021

Weird bug that I'm trying to sort out. A small demonstration:

>>> items = [f"{k:02d}" for k in range(1, 12)]
>>> print(items)
['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11']
>>> print(yaml.dump(items)
- '01'
- '02'
- '03'
- '04'
- '05'
- '06'
- '07'
- 08
- 09
- '10'
- '11'

This occurs

  • when specifying dump(items, Dumper=yaml.Dumper) and dump(items, Dumper=yaml.CDumper).
  • seemingly for strings beginning with 0 and ending in 8 or 9.
>>> fmts = ["{:0%id}"%k for k in range(1, 6)]
>>> print(yaml.dump([f.format(7) for f in fmts]))
- '7'
- '07'
- '007'
- '0007'
- '00007'
>>> print(yaml.dump([f.format(9) for f in fmts]))
- '9'
- 09
- 009
- 0009
- 00009
>>> print(yaml.dump([f"{k}09" for k in range(10)]))
- 009
- '109'
- '209'
- '309'
- '409'
- '509'
- '609'
- '709'
- '809'
- '909'

While adding default_style="'" to the dump helps resolve these values, it adds that styling to everything which is not desired.

Any suggestions?

@perlpunk
Copy link
Member

perlpunk commented Oct 19, 2021

It's not a bug. please see #486
Scalars starting with a zero are parsed as octal values in YAML 1.1
https://perlpunk.github.io/yaml-test-schema/schemas.html

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