Incorrect indentation with lists
See original GitHub issueWhen using indentation this seems to be applied to the value of the list instead of to the list itself, as you can see below indent=4
is applied after the leading -
and not to the list itself.
>>> print(yaml.dump(data['vars']['yaml'], indent=4, allow_unicode=True, default_flow_style=False))
list_of_dict_attr:
- attr1: value1
attr2: value2
attr3:
- item1
- item2
single_attr: value1
>>> print(yaml.dump(data['vars']['yaml'], indent=2, allow_unicode=True, default_flow_style=False))
list_of_dict_attr:
- attr1: value1
attr2: value2
attr3:
- item1
- item2
single_attr: value1
original issue https://github.com/ansible/ansible/issues/48865
Issue Analytics
- State:
- Created 5 years ago
- Reactions:32
- Comments:21 (4 by maintainers)
Top Results From Across the Web
A bulleted list or a numbered list becomes misaligned ...
This problem occurs because Word 2007 does not automatically create a tab as part of a hanging indent for a bullet in a...
Read more >The Indent Numbering Is Wrong on My Outline in Word
Word provides tools for fixing your lists if your numbers are out of order, the wrong combination of symbols are used or the...
Read more >Consistent list indentation - CSS: Cascading Style Sheets | MDN
One of the most common style changes made to lists is a change in the indentation distance—that is, how far the list items...
Read more >How To Avoid Indentation Error In Python
While coding you are using both the tab as well as space. · While programming you have placed an indentation in the wrong...
Read more >Python indentation error when creating a list
It's look like you have tabs with spaces mix in your code. Symple copy-paste of your code from your question works correctly.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From my point of view, the most widely-accepted indentation style for sequences is the one used multiple times in the official YAML specification. For instance, in section 2.1, example 2.3 looks like this:
The question is whether tools like
pyyaml
should render sequences in such a way for indentation of size 4 or for indentation of size 2.I would argue that it seems incorrect to render sequences in such a way for indentation of size 4, because other items would visually appear to be indented more:
Therefore, I think that it is more appropriate to render sequences in such a way for indentation of size 2:
That being said, someone may prefer to not indent sequence items to a level that is visually similar to the indentation level of the other items. That is a fair requirement, but in order to fully support it, there would have to be a separate configuration option for indentation size of sequences.
The workaround mentioned above: