List dumping should count total chars
- Dominant language
- Python
- Stars
- 424
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
The current version counts the number of elements in the list to determine whether it should be inline or not.
https://github.com/beetbox/confuse/blob/c244db70c6c2e92b001ce02951cf60e1c8793f75/confuse/yaml_util.py#L128-L131
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:
```yaml
include_regexes:
episode: ['.*?/(?P[^/]+?)(\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
1. 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.
2. As a workaround, I'd be ok if the [`Configuration.dump()`](https://github.com/beetbox/confuse/blob/c244db70c6c2e92b001ce02951cf60e1c8793f75/confuse/core.py#L639) method exposes the `default_flow_style` parameter as a keyword argument, so that we can enforce no inlining of lists.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in confuse/yaml_util.py at lines 128-131 to trace how list length currently controls flow style, then inspect confuse/core.py at Configuration.dump() around line 639 and the PyYAML API. Done means long list elements no longer produce unwieldy inline output, while the proposed default_flow_style option remains an alternative if character-based sizing is not feasible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100