PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

Tuple sorting doesn't consider profile #1815

Open kasium opened 3 years ago

kasium commented 3 years ago

The tuple, list, etc sorting options don't consider the profile option.

Code:

# isort: tuple
data = ("therearesuperlong", "therearesuperlong", "therearesuperlong", "therearesuperlong", "therearesuperlong")

isort dummy.py --profile black

# isort: tuple
data = ('therearesuperlong', 'therearesuperlong', 'therearesuperlong', 'therearesuperlong',
 'therearesuperlong')

black dummy.py

# isort: tuple
data = (
    "therearesuperlong",
    "therearesuperlong",
    "therearesuperlong",
    "therearesuperlong",
    "therearesuperlong",
)

I would expect that these sorting options consider the profile as normal. Also, the sorting options are not documented but noted here #1358

jherman3 commented 3 years ago

I'm also experiencing this with # isort: list. It'd be great to have this so we can sort __all__.

tueda commented 3 years ago

The same for # isort: unique-tuple, # isort: unique-list, #isort: set and # isort: dict. I would like to use # isort: unique-tuple for __all__ that contains many members.

tueda commented 2 years ago

Actually, the tuple sorting should follow the multi_line_output option (or possibly a similar new option for the tuple sorting) rather than the profile.

As a first step, it would be OK if the output is compatible with black (as described in #1358), but in general literal.assignment needs to implement calling a variant of wrap.import_statement. (Maybe the author is aware of it, but he is too busy to implement it...)

timothycrosley commented 2 years ago

This is true for all literal / type sorts, and is why they aren't documented / advertised features, even though If they were in a good spot I would do so because I think they are useful!

As a first step, it would be OK if the output is compatible with black (as described in #1358), but in general literal.assignment needs to implement calling a variant of wrap.import_statement. (Maybe the author is aware of it, but he is too busy to implement it...)

That's exactly right, I've just been busy, will accept PRs for this or will get to it at some point