yaml / pyyaml

Canonical source repository for PyYAML
MIT License
2.54k stars 515 forks source link

yaml dump outputs not-to-spec keys #774

Open zack-littke-smith-ai opened 9 months ago

zack-littke-smith-ai commented 9 months ago

When calling yaml.dump({"y": 1}) I end up with:

y: 1

Which makes sense, until one considers that this key (y) is actually a boolean according to the yaml spec, and is parsed as such by other yaml parsers (for example: https://pkg.go.dev/sigs.k8s.io/yaml) which would read this as:

true: 1

I would instead expect this output from yaml.dump:

"y": 1

I realize that default_style='"' is an option for me, however the written result is extremely verbose / different from a standard yaml file, pretty much defeating the purpose of using yaml in the first place.

Goofy yaml decision aside, I'm quite surprised to find a standard python lib deviating from the spec in this way.

perlpunk commented 9 months ago

There are many issues related to that, see #486 and especially #247 A PR #555 which supports YAML 1.2 is ready, but the decision was made that this should only be available with a new kind of API #700

Then it would be easy to define a "corrected" YAML 1.1 tagset along with the backwards compatible one.

zack-littke-smith-ai commented 9 months ago

Thanks! I imagine each instance of this sort of issue is quite specific, so did not find those. Feel free to close as dupe, or leave open if you'd prefer to close it alongside the fix.