This is probably the most annoying default in PyYAML. It's the only PyYAML FAQ
entry: https://pyyaml.org/wiki/PyYAMLDocumentation#frequently-asked-questions
Changing the default to always prefer indented/block style would be good, but
is not back compatible. Since we will be breaking backwards compat big time
with the upcoming safe-load-by-default changes, this change should probably be
timed with that one.
Hmm. It looks like there are actually three flow styles: True, False, and None:
>>> a = dict(a=dict(b=dict(a = ['a','b']), foo=45), c=dict(z=[1,2,3],yy=[4,5,6,7],zozo='Hey!'))
>>> print yaml.safe_dump(a)
a:
b:
a: [a, b]
foo: 45
c:
yy: [4, 5, 6, 7]
z: [1, 2, 3]
zozo: Hey!
>>> print yaml.safe_dump(a, default_flow_style=False)
a:
b:
a:
- a
- b
foo: 45
c:
yy:
- 4
- 5
- 6
- 7
z:
- 1
- 2
- 3
zozo: Hey!
>>> print yaml.safe_dump(a, default_flow_style=True)
{a: {b: {a: [a, b]}, foo: 45}, c: {yy: [4, 5, 6, 7], z: [1, 2, 3], zozo: Hey!}}
This isn't clear from the documentation: there is the FAQ which mentions use of default_flow_style=False, and later on it mentions:
The
flow_styleflag indicates if a collection is block or flow. The possible values areNone,True,False.
But there's no mention of what None, True, and False do. (flow = True, block = False, None = library picks whichever is better, right? I'm not sure.)
Fixed in https://github.com/yaml/pyyaml/commit/f20936573840842954b933801abeeaedad977b41, unless I am mistaken.
yep, fixed by #256
None != False
I like the default_flow_style=None formatting the best.
Most helpful comment
Hmm. It looks like there are actually three flow styles: True, False, and None:
This isn't clear from the documentation: there is the FAQ which mentions use of
default_flow_style=False, and later on it mentions:But there's no mention of what
None,True, andFalsedo. (flow = True, block = False, None = library picks whichever is better, right? I'm not sure.)