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

length_sort separately from regular imports and from...imports #1232

Closed
warsaw opened this issue Jun 17, 2020 · 4 comments · Fixed by #1373
Closed

length_sort separately from regular imports and from...imports #1232

warsaw opened this issue Jun 17, 2020 · 4 comments · Fixed by #1373
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@warsaw
Copy link

warsaw commented Jun 17, 2020

A style I adopted long ago (from Guido IIRC) was to sort the regular imports by length first then alphabetical, while sorting from...imports alphabetically only. E.g.

import os
import sys
import datetime

from contextlib import ExitStack
from datetime import timedelta

However this doesn't seem possible, since length_sort is a single configuration for both sections. If I set length_sort = false I get:

# These are sorted in the wrong order.
import datetime
import os
import sys

# These are sorted correctly.
from contextlib import ExitStack
from datetime import timedelta

and if I set length_sort = true I get:

# These are sorted correctly.
import os
import sys
import datetime

# These are sorted in the wrong order.
from datetime import timedelta
from contextlib import ExitStack

Neither of which I actually want. Can you add a setting to split regular import sorting from from...import sorting?

Thanks for a great tool!

@warsaw
Copy link
Author

warsaw commented Jun 17, 2020

This also affects sorting within multiline from...imports:

I want this:

from flufl.lock._lockfile import (
    AlreadyLockedError, Lock, LockError, NotLockedError, SEP, TimeOutError)

But I get this:

from flufl.lock._lockfile import (
    SEP, Lock, LockError, TimeOutError, NotLockedError, AlreadyLockedError)

@timothycrosley timothycrosley added the enhancement New feature or request label Jun 19, 2020
@timothycrosley
Copy link
Member

I'm def open to supporting this! Will have to be post 5.0.0 as I'm pretty heads down getting that out the door. Then I'll revisit. Thanks for the suggestion!

@warsaw
Copy link
Author

warsaw commented Jun 19, 2020

Sure thing! Thanks for the great tool!

@timothycrosley
Copy link
Member

This has been deployed in release 5.4.0

Thanks!

~Timothy

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

Successfully merging a pull request may close this issue.

2 participants