psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.72k stars 2.43k forks source link

black makes functions and collections too high when they are too long #4474

Closed ljhshuai closed 2 hours ago

ljhshuai commented 2 hours ago
# short line is ok
dict1 = {long_name_items, long_name_items, long_name_items, long_name_items}

# long line (more than --line-length) will cause one item per line:
# it looks too high, especially when the collection has many items
# and the last comma cannot be removed
dict2 = {
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
    long_name_items,
}

# I want like this:
dict2 = {
    long_name_items, long_name_items, long_name_items, long_name_items,
    long_name_items, long_name_items, long_name_items, long_name_items,
    long_name_items, long_name_items
}
ljhshuai commented 2 hours ago

functions with too many long arguments will have the same problem

JelleZijlstra commented 2 hours ago

This is Black's established style and we're not going to change it. Our style promotes consistent formatting where each item is separated clearly.