Is 'yes' really an alias for 'true' according to the YAML 1.1 spec? The 1.2 spec?
Question:
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?
Answers:
Interpreting yes
/no
as true
/false
in yaml spec 1.1 was intentional and by design and is documented. However in yaml spec 1.2, interpreting yes
/no
as true
/false
was dropped.
From the PyYAML Documentation,
PyYAML supports the YAML 1.1 standard, ruamel.yaml
supports YAML 1.2
as released in 2009.
YAML 1.2 dropped support for several features unquoted Yes
, No
, On
, Off
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
Both yaml 1.1 and 1.2 are being used nowadays, so it is possible to have parser for 1.2 and syntax highlight for 1.1 at the same time, which may be confusing.
syntax/yaml.vim in neovim0.8.2 is for yaml 1.2, and it involves 3 schemes: json
, core
, pyyaml
. (Note also failsave
)
That may answer this
my editor is even highlighting "yes/no" as special
Note the line
syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials
pyyaml: based on yaml 1.1, and is working in progress to add support for the YAML 1.2 Core and JSON schemas
pyyaml is popular:
ruamel-yaml : a YAML 1.2 loader/dumper package for Python
it is a derivative of pyyaml 3.11 (as on 2023-01-29, the latest pyyaml is 6.0). It’s on sourceForge instead of github.
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?
Interpreting yes
/no
as true
/false
in yaml spec 1.1 was intentional and by design and is documented. However in yaml spec 1.2, interpreting yes
/no
as true
/false
was dropped.
From the PyYAML Documentation,
PyYAML supports the YAML 1.1 standard,
ruamel.yaml
supports YAML 1.2
as released in 2009.YAML 1.2 dropped support for several features unquoted
Yes
,No
,On
,Off
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
Both yaml 1.1 and 1.2 are being used nowadays, so it is possible to have parser for 1.2 and syntax highlight for 1.1 at the same time, which may be confusing.
syntax/yaml.vim in neovim0.8.2 is for yaml 1.2, and it involves 3 schemes: json
, core
, pyyaml
. (Note also failsave
)
That may answer this
my editor is even highlighting "yes/no" as special
Note the line
syn keyword yamlBool true True TRUE false False FALSE yes Yes YES no No NO on On ON off Off OFF contained containedin=@yamlScalarWithSpecials
pyyaml: based on yaml 1.1, and is working in progress to add support for the YAML 1.2 Core and JSON schemas
pyyaml is popular:
ruamel-yaml : a YAML 1.2 loader/dumper package for Python
it is a derivative of pyyaml 3.11 (as on 2023-01-29, the latest pyyaml is 6.0). It’s on sourceForge instead of github.