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

YAML Formatting #12

Open
raunakdoesdev opened this issue Feb 2, 2021 · 2 comments
Open

YAML Formatting #12

raunakdoesdev opened this issue Feb 2, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@raunakdoesdev
Copy link
Collaborator

YAML lists should be formatted compactly as [1, 2, 3, 4] rather than

- 1
- 2
- 3
- 4
@raunakdoesdev raunakdoesdev self-assigned this Feb 2, 2021
@raunakdoesdev raunakdoesdev added the enhancement New feature or request label Feb 2, 2021
@raunakdoesdev raunakdoesdev pinned this issue Feb 2, 2021
@raunakdoesdev raunakdoesdev unpinned this issue Feb 2, 2021
@raunakdoesdev
Copy link
Collaborator Author

I think this issue can be managed by the default_flow_style kwarg. Should I change the default kwarg to be "default_flow_style=True"? @zhijian-liu

@zhijian-liu
Copy link
Owner

Thanks! I actually tried to tweak this before; however, it does not work as expected.

Here is a sample testing code:

import yaml
import tempfile

configs = {
    'a': 1,
    'b': [1, 2, 3, 4],
    'c': {
        'd': 1
    }
}

for default_flow_style in [True, False, None]:
    print(yaml.dump(configs, default_flow_style=default_flow_style))

The output of default_flow_style=True is

{a: 1, b: [1, 2, 3, 4], c: {d: 1}}

The output of default_flow_style=False is

a: 1
b:
- 1
- 2
- 3
- 4
c:
  d: 1

The output of default_flow_style=None is

a: 1
b: [1, 2, 3, 4]
c: {d: 1}

I somehow expect a mixture of the last two:

a: 1
b: [1, 2, 3, 4]
c:
  d: 1

Would love to know what you think. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants