Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to sort literals #1358

Closed
timothycrosley opened this issue Jul 31, 2020 · 5 comments
Closed

Ability to sort literals #1358

timothycrosley opened this issue Jul 31, 2020 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@timothycrosley
Copy link
Member

timothycrosley commented Jul 31, 2020

isort should provide the capability to sort all common built-in non-complex literal types. Initially, it would only need to support non dynamic ones understandable by ast.literal_eval, but long term could support even complex definitions using ast parsing. Importantly the output format should be compatible with black by default and should be ran by any configured format function.

# isort: list
__all__ = ["b", "a", "c"]

would be come:

# isort: list
__all__ = ["a", "b", "c"]

There should be an additional option to dedup lists for the user (sets and others than are deduped within python should auto dedup):

# isort: unique-list
__all__ = ["a", "a", "b", "c"]

would become:

# isort: unique-list
__all__ = ["a", "b", "c"]

This supersedes #392

@timothycrosley
Copy link
Member Author

This is finished in develop and will be released in the 5.3.0 release.

@blthayer
Copy link

blthayer commented Nov 29, 2021

Hello @timothycrosley!

Sorry for the silly question, but I'm having trouble finding how to turn this functionality on within isort. I was unable to find any references to literal or __all__ within the options, and my manual reading/skimming didn't come up with anything obvious.

Is it possible to turn on sorting of __all__ via the isort CLI?

@jugmac00
Copy link
Contributor

@blthayer Have you found out how to sort __all__ meanwhile?

@blthayer
Copy link

@blthayer Have you found out how to sort __all__ meanwhile?

@jugmac00 - I have not, unfortunately. I just sort of dropped it as "not worth it for now" 😄

Good luck, and if you find something I'd love to hear about it!

@jugmac00
Copy link
Contributor

Looks like I figured it out 😉

#1887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants