Is there a setting to change the sort order of relative imports from
from .. import x
from . import y
to
from . import y
from ..import x
so that one can comply with the Google style guide as per this linter https://github.com/public/flake8-import-order#configuration?
Hi @lee-kagiso,
Thanks for bringing this to my attention! This is not something isort currently supports, but I'll work on adding support for this in the next release.
Thanks!
~Timothy
This is fixed as the default (no config necessary) and will be pushed into a new release today.
Thanks!
~Timothy
Let me start by saying thank you for isort. It has made a positive impact on my personal and team's workflows!
Although the referenced flake8-import-order plugin may reject the descending order for relative imports, AFAICT the Google Python Style Guide makes no assertions about order of relative imports. In fact, it prohibits using relative imports at all:
Do not use relative names in imports. Even if the module is in the same package, use the full package name. This helps prevent unintentionally importing a package twice.
To be clear, by descending order, I mean:
from ...baz import x
from ..foo import y
from .bar import z
There are at least two arguments for isort to default to descending order for relative imports:
isort's previous behavior for imports of the form from ..module import name, which more common in my projects than the from .. import module form.... are less local than those from .., and imports from . are most local. Descending relative imports achieves this ordering.The original intent of this issue was to add an option to select the order of relative imports. I suggest that such an option remains a valid request for isort.
I agree with @jpgrayson, with the recent release of isort it suddenly started reversing imports that were perfectly fine before.
Most helpful comment
Let me start by saying thank you for
isort. It has made a positive impact on my personal and team's workflows!Although the referenced
flake8-import-orderplugin may reject the descending order for relative imports, AFAICT the Google Python Style Guide makes no assertions about order of relative imports. In fact, it prohibits using relative imports at all:To be clear, by descending order, I mean:
There are at least two arguments for
isortto default to descending order for relative imports:isort's previous behavior for imports of the formfrom ..module import name, which more common in my projects than thefrom .. import moduleform....are less local than those from.., and imports from.are most local. Descending relative imports achieves this ordering.The original intent of this issue was to add an option to select the order of relative imports. I suggest that such an option remains a valid request for
isort.