yaml.dump has unintuitive defaults
yaml.dump(dictionary) outputs a string for a dictionary.
yaml.dump(dictionary, default_flow_style=False) outputs a yaml string.
Seeing as this is a yaml library and all assumptions would point to outputting a yaml string as the default, these defaults seem kind of confusing and unintuitive.
I agree with you. I'll probably start working on this over on sigmavirus24/pyyaml
Is this still an issue? @jonchu I'm missing an example. I can't see how pyyaml was behaving in 2012, but it could be that you were just seeing flow style YAML instead of block style.
PyYAML has always dumped non-nested dicts in the flow style (looks like JSON or Python) by default:
>>> yaml.dump({'a': 1, 'b': 2})
'{a: 1, b: 2}\n'
>>> yaml.dump({'a': 1, 'b': 2}, default_flow_style=False)
'a: 1\nb: 2\n’
Never liked that default, but that’s the way it is.
I suspect you thought the default output was a python string, like this:
>>> {'a': 1, 'b': 2}
{'a': 1, 'b': 2}
>>> repr({'a': 1, 'b': 2})
"{'a': 1, 'b': 2}"
But notice how the a and b keys are quoted...
Closing this issue.
Saying "I never liked the default, but that's the way it is" seems...not good. I'd expect a YAML library to output YAML that's easy for humans to read and avoids "flow style" and tags wherever possible. It's really quite annoying to continually have to fight the defaults for this library to get sane and normal YAML output.
@robbieh I can't imagine that changing the default would not break a lot of stuff. I'm sure YAML dumps must be used in a lot of testing, and this has always been the default.
Can you think of a way that we can change this default responsibly?
See #199
It possible to reopen issues on github. Closing issue #1 just to create a new issue #199 with exactly the same problem, seems strange choice. Why do that?
Yes it's not possible to change it backwards compat, but it can (and should) be changed it in a major version release.