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

bug? some string constants are getting printed as ints #773

Closed
brigadier opened this issue Dec 10, 2023 · 2 comments
Closed

bug? some string constants are getting printed as ints #773

brigadier opened this issue Dec 10, 2023 · 2 comments

Comments

@brigadier
Copy link

l = range(0, 10)
for i in l: yaml.dump(['0' + str(i)])

Result:

... 
"- '00'\n"
"- '01'\n"
"- '02'\n"
"- '03'\n"
"- '04'\n"
"- '05'\n"
"- '06'\n"
"- '07'\n"
'- 08\n'
'- 09\n'

Is this supposed to be so?
I'm on python 3.8, pyyaml v. 5.3.1

@haojiezhe12345
Copy link

I'm using pyyaml 6.0.1 on python 3.12, still encountering the bug

@nitzmahone
Copy link
Member

nitzmahone commented Feb 5, 2024

This isn't really a bug- it's consistent and correct behavior for roundtripping values in YAML 1.1 (which is all PyYAML currently supports). The default emitter config won't quote string values unless not quoting them would cause a similarly-configured loader to treat them as a non-string. The default 1.1 type configuration recognizes strings matching 0[0-7]+ as octal ints, so strings matching that need to be quoted to prevent the loader seeing them as octals, but 0[89] do not.

@nitzmahone nitzmahone closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
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

4 participants
@brigadier @nitzmahone @haojiezhe12345 and others