list indention style is different from pyyaml
See original GitHub issueconsider the following pyyaml
code (try yourself):
import yaml
print yaml.dump(
{
"foo": [1, 2, 3]
},
default_flow_style=False
)
which outputs
foo:
- 1
- 2
- 3
and the comparable js-yaml
counterpart (try yourself):
const yaml = require("js-yaml");
console.log(
yaml.safeDump({
foo: [1, 2, 3]
})
);
which outputs
foo:
- 1
- 2
- 3
You can see that pyyaml
doesn’t add spaces to lists (because -
counts as indention). I know both are valid, but it would be great if we could a similar output as pyyaml
(especially as this project started as some kind of fork)?
Changing this line to
writeBlockSequence(state, level - 1, state.dump, compact);
changes the behaviour so it should be possible to add a configuration setting to allow both behaviours.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:15 (11 by maintainers)
Top Results From Across the Web
Incorrect indentation with lists #234 - yaml/pyyaml - GitHub
When using indentation this seems to be applied to the value of the list instead of to the list itself, as you can...
Read more >python yaml.dump bad indentation - Stack Overflow
I ran into this problem generating data files for OpenCV . The OpenCV YAML parser requires the extra indent. Otherwise it throws an...
Read more >Tips that may save you from the hell of PyYAML | Reorx's Forge
By default, PyYAML indent list items on the same level as their parent. ... This is not a good format according to style...
Read more >Details — Python YAML package documentation
PyYAML (and older versions of ruamel.yaml) gives you non-indented scalars (when ... style collections (mappings/sequences resuting in Python dict/list).
Read more >PyYAML Documentation
By default, PyYAML chooses the style of a collection depending on whether it has nested collections. If a collection has nested collections, it...
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 Free
Top 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
You request a breaking change without valuable profit (at least, i could not understand it) - i don’t like such balance.
And I do totally agree. But it’s not that the proposal is completely messing with the output (let’s configure an option to dump XML), but a different behaviour others have adopted.
My use case (and I can think of others): Some different tool chains work with a YAML content, and
git blame
will refer to whitespace- instead of content changes)