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

Sort by length doesn't really sort by length #2304

Open
scarere opened this issue Nov 20, 2024 · 0 comments
Open

Sort by length doesn't really sort by length #2304

scarere opened this issue Nov 20, 2024 · 0 comments

Comments

@scarere
Copy link

scarere commented Nov 20, 2024

Please see the following issue that I raised with ruff: issue

The gist is I can't get isort to truly sort by length as for statements that use the from keyword to import modules, eg:

from package.subpackage.module import function

It does not count anything including or after the import statement towards the line length. For example, when sorting by line length the output would be something like this.

from package.short.path import more_functions, another_function
from package.with.long.path import fn

I'm not sure if this is intended but for me personally it seems to make more sense that the total line length should be taken into account, not just the length of the module.

P.S. As a side note, as a possible new feature, it would be really great if there was an option to import statements that span multiple lines at the bottom of the section, sort of in a subsection. I say subsection because ideally the main sections could have line breaks but the subsections wouldn't. Something like the following would be really cool

import x
from x import y
from x.subpackage.module import function1
from x.module import (
    function2,
    function3,
    function4,
    function5,
)

import k  # New section
from k.subpackage.module import j
from k.module import (
    fn1,
    fn2,
    fn3,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant