Ticket #184 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

Invalid sequence handling

Reported by: nick.demyanchuk@… Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:


Pyyaml improperly dumps sequence block. For example:

>>> from yaml import load, dump

>>> cfg = """key:
              - value
              - another one
              - foo

>>> yaml_dict = load(cfg)

>>> print yaml_dict
{'key': ['value', 'another one', 'foo']}

>>> new_cfg = dump(yaml_dict)

>>> print new_cfg
key: [value, another one, foo]


Change History

comment:1 follow-up: ↓ 2 Changed 3 years ago by anonymous

This is how it should be. What is your expectation ? You can check your document here:

%YAML 1.1
!!map {
    ? !!str "key"
    : !!seq [
        !!str "value",
        !!str "another one",
        !!str "foo",

Do you mean you expect the flow style ?

From the documentation (

By default, PyYAML chooses the style of a collection depending on whether it has nested collections. If a collection has nested collections, it will be assigned the block style. Otherwise it will have the flow style.

If you want collections to be always serialized in the block style, set the parameter default_flow_style of dump() to False.

comment:2 in reply to: ↑ 1 Changed 3 years ago by anonymous

Thank you! default_flow_style works excellent.

comment:3 Changed 3 years ago by xi

  • Status changed from new to closed
  • Resolution set to invalid

Add a comment

Modify Ticket

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.