I think it should be consistent.

The first line establishes an indentation width of 2 spaces.

The second line is a list element that itself is a map of one entry, and
your multi-line text is the value for this entry.

Since it is nested, in effect we need to indent twice, and so I think that
is why 4 spaces works when 2 does not in this case.

On Fri, Apr 26, 2019 at 2:32 PM Walt Karas <wka...@verizonmedia.com.invalid>
wrote:

> So, it seems that with YAML, it sometimes matters whether you use 4 spaces
> of indentation rather that 2 space of indentation.  Is there some reason we
> are choosing to use YAML, other than sheer love of Satan?
>
> $ cat load.py
>
> import yaml
>
> import sys
>
> f = open(sys.argv[1], 'r')
>
> y = yaml.load(f)
>
> print(y)
>
> $
>
> $ cat y1.yaml
>
> a:
>
>   - b: |
>
>       one
>
>       two
>
>   - c: |
>
>       three
>
>       four
>
> $
>
> $ cat y2.yaml
>
> a:
>
>   - b: |
>
>     one
>
>     two
>
>   - c: |
>
>     three
>
>     four
>
> $
>
> $ python load.py y1.yaml
>
> {'a': [{'b': 'one\ntwo\n'}, {'c': 'three\nfour\n'}]}
>
> $
>
> $ python load.py y2.yaml
>
> Traceback (most recent call last):
>
>   File "load.py", line 4, in <module>
>
>     y = yaml.load(f)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/__init__.py", line 71,
> in load
>
>     return loader.get_single_data()
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/constructor.py", line
> 37, in get_single_data
>
>     node = self.get_single_node()
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 36,
> in get_single_node
>
>     document = self.compose_document()
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 55,
> in compose_document
>
>     node = self.compose_node(None, None)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 84,
> in compose_node
>
>     node = self.compose_mapping_node(anchor)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 133,
> in compose_mapping_node
>
>     item_value = self.compose_node(node, item_key)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 82,
> in compose_node
>
>     node = self.compose_sequence_node(anchor)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 111,
> in compose_sequence_node
>
>     node.value.append(self.compose_node(node, index))
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 84,
> in compose_node
>
>     node = self.compose_mapping_node(anchor)
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 127,
> in compose_mapping_node
>
>     while not self.check_event(MappingEndEvent):
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/parser.py", line 98, in
> check_event
>
>     self.current_event = self.state()
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/parser.py", line 428,
> in parse_block_mapping_key
>
>     if self.check_token(KeyToken):
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/scanner.py", line 115,
> in check_token
>
>     while self.need_more_tokens():
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/scanner.py", line 149,
> in need_more_tokens
>
>     self.stale_possible_simple_keys()
>
>   File "/usr/local/lib/python2.7/site-packages/yaml/scanner.py", line 289,
> in stale_possible_simple_keys
>
>     "could not find expected ':'", self.get_mark())
>
> yaml.scanner.ScannerError: while scanning a simple key
>
>   in "y2.yaml", line 3, column 5
>
> could not find expected ':'
>
>   in "y2.yaml", line 4, column 5
>

Reply via email to