-
Notifications
You must be signed in to change notification settings - Fork 518
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
'0008' and '0009' strings are not single-quoted when dumping. #740
Comments
There is a similar issue when parsing this data from text: import yaml
text = '''
0007: {key: val}
0008: {key: val}
0009: {key: val}
0010: {key: val}
'''
data = yaml.safe_load(text)
print(data.keys()) This produces |
You're running afoul of the YAML 1.1 base-8 integer representation. This is all "legit" through that lens, since PyYAML currently only supports YAML 1.1. It sucks, which is why octals got revamped in YAML 1.2 (and there are numerous ways to disable/bypass that behavior), but it's not a bug. Since it sounds like you're interopping with another YAML implementation that's reading those as 0-padded base-10 ints (1.2 behavior), you'd probably do better to quote or Closing as "not a bug, just an unfortunate reality until PyYAML grows proper 1.2 support". |
Thank you @nitzmahone, for the answer and suggestion! My process involved emitting YAML from The real problem occurred in the When With @nitzmahone's suggestion above, I modified my static Node encode(const ExampleStructure& rhs)
{
Node node;
node["data"] = rhs.data;
node["name"] = rhs.name;
node["name"].SetTag("tag:yaml.org,2002:str");
return node;
} That tagged the appropriate data elements in the YAML emitted by |
I'm using pyyaml version 6.0.1 and I've discovered that strings that end in '8' and '9' that are prefixed with at least one '0' are treated differently than strings ending with any other digit. This is problematic in that other interpreters (namely
yaml-cpp
) then fail to properly interpret the data as a string.After diving into the
resolver.py
code, it looks like this is because of this regex, which matches '0007' but does not match '0008' or '0009'.Here is a minimal example:
The resulting file looks like:
The text was updated successfully, but these errors were encountered: