Menu

#409 Ruamel.yaml comsiders two merge keys as a duplicate key

closed
nobody
None
minor
bug
2021-12-25
2021-11-27
No
>>> ruamel.yaml.safe_load("""
... .foo: &foo
...   hello: world
... 
... .bar: &bar
...   baz: qux
... 
... all:
...   <<: *foo
...   <<: *bar
... """)
Traceback (most recent call last):
   [...]
    raise DuplicateKeyError(*args)
ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
  in "<unicode string>", line 9, column 3:
      <<: *foo
      ^ (line: 9)
found duplicate key "<<"
  in "<unicode string>", line 10, column 3:
      <<: *bar
      ^ (line: 10)

To suppress this check see:
   http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys

Expected output would be:

{'.foo': {'hello': 'world'},
 '.bar': {'baz': 'qux'},
 'all': {'hello': 'world', 'baz': 'qux'}}

or at least to not barf.

Discussion

  • Daniele Varrazzo

    I've just found the syntax <<: [*foo, *bar] as a workaround. If that's actually the only way - as spec - to define multiple merge, please feel free to close. Thank you!

     
  • Anthon van der Neut

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,4 +1,3 @@
    -
     ~~~
     &gt;&gt;&gt; ruamel.yaml.safe_load(&#34;&#34;&#34;
     ... .foo: &amp;foo
    
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB