You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been writing Python for over a decade and I've ultimately arrived at this approach that has not changed in a few years. From what I can tell this can't be done with isort, but maybe I didn't find the right settings:
This is how my organisation typically looks like in my code:
from __future__ importannotationsimportosimportrequestsfromtypingimportAnyfromtypingimportDict
The first block contains all __future__ imports, sorted by name.
The second block contains all import directives, sorted by name.
The third block contains all from directives, sorted by name.
I do not use any commas in my imports, that means I never do from foo import bar, baz. I've stopped doing that at some point as it makes for easier sorting and nicer Git histories.
Basically what I do is write my import in the right block, then sort the block.
Any way isort can support this style? Thanks for letting me know.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I've been writing Python for over a decade and I've ultimately arrived at this approach that has not changed in a few years. From what I can tell this can't be done with isort, but maybe I didn't find the right settings:
This is how my organisation typically looks like in my code:
__future__
imports, sorted by name.import
directives, sorted by name.from
directives, sorted by name.I do not use any commas in my imports, that means I never do
from foo import bar, baz
. I've stopped doing that at some point as it makes for easier sorting and nicer Git histories.Basically what I do is write my import in the right block, then sort the block.
Any way isort can support this style? Thanks for letting me know.
Beta Was this translation helpful? Give feedback.
All reactions