I’m trying to debug an issue, and it boils down to…
>>> import yaml as pyyaml >>> import ruamel.yaml as ruamel >>> ruamel.load("x: yes") == ruamel.load("x: true") False >>> pyyaml.safe_load("x: yes") == pyyaml.safe_load("x: true") True
There are rumors on the internet about “yes” and “no” being reserved words that are also synonyms for true
and false
respectively.
But there is only passing mention in the 1.1 spec but no elaboration, and the string “yes” doesn’t appear in the 1.2 spec at all.
In fact looking through every draft of the spec it only appears in a legitimate way in any kind of legitimate way in https://yaml.org/spec/history/2002-09-01.html and is removed in the revision after.
I suspect I’ve answered my own question in the course of writing it, but… is this business about “yes/no” just nonsense that made its way into implementations (my editor is even highlighting “yes/no” as special), or am I misunderstanding or missing part of the spec?
Advertisement
Answer
It is difficult to compare YAML 1.2 and YAML 1.1 in this area. YAML 1.2 has schemas which are absent in YAML 1.1.
None of the schema’s mentioned in the YAML 1.2 specification (base, json, core) mention Yes
as a boolean type, and the examples don’t use these anymore, where the YAML 1.1 still had these.
The YAML 1.2 specification however does mention possible schema’s beyond the core schema, including parts of the language independent type repository Unfortunately there are areas in that repository, that contradict YAML 1.2 (such as how octals are represented). So a generic fully 1.1 compatible in YAML 1.2 is impossible.
Given the non-mention of Yes
as a boolean, and the general confusion it caused (there are question about why Yes
was quoted when dumped here on SO), I decided to drop support for that when I implemented YAML 1.2 support in ruamel.yaml
. Other, less confusing (IMO) and useful things like the merge key (<<
) are in ruamel.yaml
(and so are less useful elements like the value key).
PyYAML however only supports the YAML 1.1 standard (that was replaced in 2009).
If your document isn’t implicit, but has a header:
%YAML 1.1 --- x: yes
Then ruamel.yaml
will load yes
as boolean as well, as ruamel.yaml
defaults to loading YAML 1.2 by default, whereas PyYAML still only (partly) supports loading of YAML 1.1