Invalid output from round-trip dumper with indented list + comment + mapping as list item

Issue #162 invalid
Mike Kazantsev
created an issue
#!/usr/bin/env python3

import os, sys, io
import ruamel.yaml

yaml_str = '''
some-list:
  # mapping value below causes issue
  - {}

mapping-A:
  mapping-B:
    mapping-C:
'''

yaml = ruamel.yaml.YAML(pure=True)
with io.StringIO(yaml_str) as src: data = yaml.load(src)
yaml.dump(data, sys.stdout)

output:

some-list:
  # mapping value below causes issue
- {}

mapping-A: mapping-B:
    mapping-C:

expected output:

some-list:
  # mapping value below causes issue
- {}

mapping-A: 
  mapping-B:
    mapping-C:

Workarounds (doing any of these will fix it):

  • Remove comment.
  • Un-indent list item.
  • Use something else as list item value.

Versions:

  • ruamel.yaml version: 0.15.34
  • python sys.version: 3.6.2 (default, Jul 20 2017, 03:52:27) \n[GCC 7.1.1 20170630]

Comments (2)

  1. Mike Kazantsev reporter

    Similar to #164, I believe this is a problem with inconsistent indentation in sequences, which I mistakenly believed I understood with YAML (likely because PyYAML is very forgiving) - wasn't the case.

    Sorry for the noise.

  2. Log in to comment