question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

list indention style is different from pyyaml

See original GitHub issue

consider 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
puzrincommented, Jul 5, 2018
  • Probably, “most of frameworks” just are just binding to libyaml. There are no standard OR recommendations about better output look.
  • “needless whitespaces” is not good argument, because yaml is about readability, not about size optimizations

You request a breaking change without valuable profit (at least, i could not understand it) - i don’t like such balance.

2reactions
thewillicommented, Oct 22, 2018

Adding “everything possible” make API messy very quickly.

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.

I’d like to understand, what’s wrong right now? Output is valid yaml. Other yaml parser should accept it ok.

My use case (and I can think of others): Some different tool chains work with a YAML content, and

  • detect changes when they are aren’t any (because only whitespace has changed)
  • YAML files checked in a VCS like git will pollute the history with whitespace changes, complicating to work with actual changes (git blame will refer to whitespace- instead of content changes)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found