Isort: The -k/--keep-direct-and-as flag does not work

Created on 14 Aug 2018  路  2Comments  路  Source: PyCQA/isort

-k, --keep-direct-and-as
                    Turns off default behavior that removes direct imports
                    when as imports exist.

But when I have file test.py:

from django.utils.translation import ugettext as _, ugettext

and run isort -k test.py or isort --keep-direct-and-as test.py, the result is:

from django.utils.translation import ugettext as _

isort version is 4.3.4.

Most helpful comment

This is fixed in develop and will make it's way out in the 5.0.0 release.

Thanks!

~Timothy

All 2 comments

I'm gonna piggyback on this issue. It seems to me that it hasn't been resolved completely. What I mean by completely is that if the "duplicate" imports are at the same line then isort will not change it and hence not break the code. However if the imports are split so that each import has it's own line e.g.

from django.utils.translation import ugettext as _
from django.utils.translation import ugettext

then when we run isort --keep-direct-and-as ./path_to_file/ will give us these results

from django.utils.translation import ugettext as _

which obviously will break the code.

isort version is 4.3.21

This is fixed in develop and will make it's way out in the 5.0.0 release.

Thanks!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings