Consider the following file:
- k0: v0
vars: &splat0
VAR0: potato # vars from blob0
- k1: v1
vars: &splat1
VAR1: spud # vars from blob1
- k: v
extra: # merged vars from blob0 + blob1
<<: *splat0
<<: *splat1
It makes use of the merge key features of YAML.
Is this a valid YAML file? The spec (1.1, 1.2) says that within a mapping node there is the "restriction that each of the keys is unique", however it is not clear whether the merge key themselves are subject to uniqueness constraint, or whether only the mapping keys after a resolved merge need to be unique.
PyYAML parses this and merges keys, but the comments are lost. ruamel is able to preserve comments but raises a DuplicateKeyError
, and if you explicitly allow duplicate keys then it parses but the merge is lost.
Is this input valid YAML and how should it be correctly parsed in Python?