You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When formatting a large single dimensional sequence (list, tuple, set) of similar sized literals (ints, floats, strings, etc.), please consider adding support a compact representation by putting multiple items on each line, similar to what other autoformaters do by default. Ruff only supports putting all of the items on a single line if they fit within the configured line length or each item on a separate line otherwise. This forces large sequences use many more lines than they need to, which requires excessive vertical scrolling and thus makes them more difficult to read and understand.
Since Ruff automatically adds a trailing comma when exploding sequences, the existing skip-magic-trailing-comma option could be used by users who want to enable this compact representation without changing any already formatted code for those who have not enabled that option.
For example, here are a few diffs from a couple of projects I recently changed from using autopep8 to Ruff. While Ruff is better is almost every regard, I would argue that a compact representation for these sequences would be a more efficient use of the available lines.
A list of floats (this preferably should have 4-5 columns of floats, so around halfway between the two extremes of 10 columns and 1 column respectfully):
A workaround is to manually format the sequences and then add a fmt: skip comment, but the point of using an autoformatter is of course to have all the code be automatically formatted. Note that all of these examples are constant/final values, which are rarely if ever expected to change, so readability is much more important than minimizing the diff on a potential future change.
$ ruff --version
ruff 0.4.8
The text was updated successfully, but these errors were encountered:
Yeah this makes sense. I very much want a better list formatting that uses less vertical space. We started some exploration in #8452 but haven't had time yet to implement any new style.
When formatting a large single dimensional sequence (list, tuple, set) of similar sized literals (ints, floats, strings, etc.), please consider adding support a compact representation by putting multiple items on each line, similar to what other autoformaters do by default. Ruff only supports putting all of the items on a single line if they fit within the configured line length or each item on a separate line otherwise. This forces large sequences use many more lines than they need to, which requires excessive vertical scrolling and thus makes them more difficult to read and understand.
Since Ruff automatically adds a trailing comma when exploding sequences, the existing
skip-magic-trailing-comma
option could be used by users who want to enable this compact representation without changing any already formatted code for those who have not enabled that option.For example, here are a few diffs from a couple of projects I recently changed from using autopep8 to Ruff. While Ruff is better is almost every regard, I would argue that a compact representation for these sequences would be a more efficient use of the available lines.
A frozenset of ints:
A list of floats (this preferably should have 4-5 columns of floats, so around halfway between the two extremes of 10 columns and 1 column respectfully):
A tuple of single character strings:
A workaround is to manually format the sequences and then add a
fmt: skip
comment, but the point of using an autoformatter is of course to have all the code be automatically formatted. Note that all of these examples are constant/final values, which are rarely if ever expected to change, so readability is much more important than minimizing the diff on a potential future change.The text was updated successfully, but these errors were encountered: