Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change dump(..., default_flow_style=...) default to False #199

Closed
ingydotnet opened this issue Jul 3, 2018 · 4 comments
Closed

Change dump(..., default_flow_style=...) default to False #199

ingydotnet opened this issue Jul 3, 2018 · 4 comments

Comments

@ingydotnet
Copy link
Member

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.

@jason-s
Copy link

jason-s commented Sep 11, 2018

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_style flag indicates if a collection is block or flow. The possible values are None, 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.)

@ingydotnet ingydotnet added this to To Do in 5.1 Release Feb 23, 2019
@ingydotnet ingydotnet removed this from Possible PRs and To Do items in 5.1 Release Feb 23, 2019
@FichteFoll
Copy link

Fixed in f209365, unless I am mistaken.

@perlpunk
Copy link
Member

yep, fixed by #256

@Ark-kun
Copy link

Ark-kun commented Apr 10, 2020

None != False
I like the default_flow_style=None formatting the best.

nforro added a commit to nforro/packit that referenced this issue Dec 8, 2020
See: yaml/pyyaml#199

Signed-off-by: Nikola Forró <nforro@redhat.com>
nforro added a commit to nforro/packit that referenced this issue Dec 8, 2020
See: yaml/pyyaml#199

Signed-off-by: Nikola Forró <nforro@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants