Why does pyyaml disallow trailing spaces in block scalars?
See original GitHub issueBlock style (|
, <
) is overruled with quoted style ("
) if the string contains trailing spaces. I don’t see any reason for this, and the fact that I can’t force a certain style (even it means losing information) has caused me a lot of grief.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:19 (7 by maintainers)
Top Results From Across the Web
How can I control what scalar form PyYAML uses for my data?
It's worth noting that pyyaml disallows trailing spaces in block scalars and will force content into double-quoted format.
Read more >YAML Multiline Strings
Block scalars have more control over how they are interpreted, whereas flow scalars ... indicator if the first line of the block starts...
Read more >YAML Superpowers, part 2: Multiline Strings
In a multi-line block, YAML first determines the indentation level of the whole block: ... The leading spaces corresponding to (implicit or ...
Read more >Details — Python YAML package documentation
PyYAML (and older versions of ruamel.yaml) gives you non-indented scalars (when ... that can be used to push the dash inwards, within the...
Read more >YAML: The Missing Battery in Python
The leading whitespace on each line defines the scope of a block, ... You can define a YAML scalar similarly to a corresponding...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you @perlpunk for these examples, they perfectly illustrate what I mean, and thank you both for looking into this.
My use case was that I had a large number of dictionaries that I wanted to store as yaml records, in
|
block style. Some of these happened to have trailing spaces and were output wrongly, as a double quoted scalar. This was frustrating because|
block style. This really boggles the mind: pyyaml is needlessly deviating from the yaml spec. So this is a bug, that should be fixed.|
block style. The way every other Python function that I know of works is that the option I set is obeyed, possibly leading to warnings and/or errors, and that the consequences (like losing information in edge cases) are for me to deal with. This is programming, I should be able to control things. For pyyaml to override my option due to style considerations really is not acceptable.My ‘solution’ was to strip trailing spaces before emitting so I would get
|
block style across the board, so ironically, this led me to lose information I wouldn’t have lost otherwise.@ingydotnet , I was trying to give examples, to every reader of this issue, where I can understand the wish for block style to be preserved. I was not writing this to imply that you don’t know how it works.