Isort: New prefix mode idea: `from module` instead of `hanging indent`

Created on 25 Feb 2019  路  9Comments  路  Source: PyCQA/isort

How amenable would you be to a sort mode that instead of doing a hanging indent, prefixes with the module?

from example import a, b, c
from example import e, f, g

this would:

  • preserve grepability
  • minimize lines
  • not conflict with autoformatter's code styles
enhancement good first issue help wanted

Most helpful comment

@jadkik this is merged in develop, and will make its way into the 5.0.0 release.

Thanks!

~Timothy

All 9 comments

That's a cool idea! isort is built to be configurable to fit every user's projects and such a feature would be consistent with this.

Okay neat., thanks! If I have some time I will try and implement this, but I'll comment before I get started, anyone else should feel free to try if they're interested.

btw: force_single_line = 1 appears to have this as a side-effect already, right?

@blueyed, the way I understand the suggestion is that force_single line would, independent of line length limit and size turn the above into:

from example import a
from example import b
from example import c
from example import e
from example import f
from example import g

Whereas the desire here is to still group (comma delimited) the imports together up until the line length is reached, and then create a new line in the same format.

If anyone decides to pick this up in the future, the place to add additional wrap modes is: https://github.com/timothycrosley/isort/blob/develop/isort/wrap_modes.py

Thanks!

~Timothy

If no one is working on this, can I take it up?

@tegkhanna go for it! I appreciate the offer to contribute! If you run into any issues, let me know how I can un-block you.

Thanks!

~Timothy

@timothycrosley Sure :) I will create a pull request soon!

I see this has been merged to develop, so it will be included in the next release?

The README on develop doesn't seem to mention the new wrap mode. I am not sure whether it will be updated once before the release or before this issue is closed.

@jadkik this is merged in develop, and will make its way into the 5.0.0 release.

Thanks!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pradyunsg picture pradyunsg  路  3Comments

jack1142 picture jack1142  路  3Comments

johnthagen picture johnthagen  路  3Comments

whg517 picture whg517  路  3Comments

ghickman picture ghickman  路  3Comments