-
Couldn't load subscription status.
- Fork 54
Open
Description
The current version counts the number of elements in the list to determine whether it should be inline or not.
Lines 128 to 131 in c244db7
| length = len(data) | |
| if self.default_flow_style is None and length < 4: | |
| node.flow_style = True | |
| elif self.default_flow_style is None: |
This works fine when the representation of the elements themselves are pretty short, but if we're storing large(-ish) strings, things get out of hand, even when the number of elements is less than 4. Here's an example for a config file I use to store user-defined regexes:
include_regexes:
episode: ['.*?/(?P<title>[^/]+?)(\s+\[[0-9]{3,4}p\])?(/S(eason)?\s*(?P<season>\d+))?/(?P<episode>\d+) - (?:.*)', '.*?/(?P<title>[^/]+?)(\s+\[[0-9]{3,4}p\])?(/S(eason)?\s*\d+)?/S(?P<season>\d+)E(?P<episode>\d+) - (?:.*)']
movie: ['.*/(?P<title>.+?) \((?P<year>[0-9]{4})\)[^/]+$']Possible solutions
- The best case scenario would be to have some way to get the total length of the elements after dump, and have a threshold on the number of chars to decide. But from my brief look over the pyyaml api, this doesn't seem to be feasible.
- As a workaround, I'd be ok if the
Configuration.dump()method exposes thedefault_flow_styleparameter as a keyword argument, so that we can enforce no inlining of lists.
agrawal-d
Metadata
Metadata
Assignees
Labels
No labels