Skip to content

Emit the correct indentation of sequence#430

Open
dota17 wants to merge 1 commit intoyaml:mainfrom
dota17:issue234
Open

Emit the correct indentation of sequence#430
dota17 wants to merge 1 commit intoyaml:mainfrom
dota17:issue234

Conversation

@dota17
Copy link

@dota17 dota17 commented Aug 26, 2020

Modify the output format of Custom indent in sequence by adding the is_qequence parameter in write_indicator().
Refer to #234, The test case is:

doc = """
%TAG !E! !SSSSS
---
- hosts: localhost
  vars:
    yaml:
      single_attr: value1
      list_of_dict_attr:
        - attr1: value1
          attr2: value2
          attr3:
            - item1
            - item2
  tasks:
    - debug: msg="{{ yaml | to_nice_yaml }}"
- 
  - aaa
  - ccc
...

the result is shown below:

print(yaml.dump(data, indent=6, allow_unicode=True, default_flow_style=False))

    - hosts: localhost
      tasks:
          - debug: msg="{{ yaml | to_nice_yaml }}"
      vars:
            yaml:
                  list_of_dict_attr:
                      - attr1: value1
                        attr2: value2
                        attr3:
                            - item1
                            - item2
                  single_attr: value1
    -     - aaa
          - ccc

print(yaml.dump(data, indent=3, allow_unicode=True, default_flow_style=False))

 - hosts: localhost
   tasks:
    - debug: msg="{{ yaml | to_nice_yaml }}"
   vars:
      yaml:
         list_of_dict_attr:
          - attr1: value1
            attr2: value2
            attr3:
             - item1
             - item2
         single_attr: value1
 -  - aaa
    - ccc

In brief, This output format is more consistent with spec.

Do I need to add the testcases in PR? @perlpunk

@perlpunk
Copy link
Member

I guess a test would be nice :)
But I'm not maintaining PyYAML or making any decisions.

@perlpunk
Copy link
Member

perlpunk commented Aug 28, 2020

One thing to keep in mind is that the output of libyaml is different. So there would be a difference between yaml.Dumper and yaml.CDumper.
That will probably be an issue with a test.

@JobaDiniz
Copy link

will this ever be merged?

@bcoca bcoca mentioned this pull request Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants