isort icon indicating copy to clipboard operation
isort copied to clipboard

`HANGING_INDENT` Multi Line Import adds comma in profile hug

Open Bengt opened this issue 4 years ago • 4 comments

I have imports like so:

from vr_backend.shims.tensorboard_shim.tensorboard_writer import \
    TensorBoardWriter

I run isort on that file like so:

venv/bin/python -m isort --profile hug --line-length=79 -m HANGING_INDENT main.py

I get superfluous commas in the imports:

from vr_backend.shims.tensorboard_shim.tensorboard_writer import \
    TensorBoardWriter,

This is not valid Python syntax and thus even causes errors when trying to execute the file:

  File "/home/bengt/Downloads/DFKI/gitlab.ni.dfki.de/VR/VR.Backend/vr_backend/vae/main.py", line 14
    TensorBoardWriter,
    ^
SyntaxError: trailing comma not allowed without surrounding parentheses

Bengt avatar Dec 06 '21 17:12 Bengt

My current workaround is to manually not check in these faulty lines. This is however cumbersome and error-prone.

On a ~ 1.3k line code base, I get this error 33 times, so it is quite widespread for me.

Bengt avatar Dec 06 '21 17:12 Bengt

According to the documentation, there should be no trailing comma in the last line of a hanging-indent multi line import:

from third_party import \
    lib1, lib2, lib3, \
    lib4, lib5, lib6

Source: https://pycqa.github.io/isort/docs/configuration/multi_line_output_modes.html#2-hanging-indent

So, I would have expected my imports to remain unchanged like so:

from vr_backend.shims.tensorboard_shim.tensorboard_writer import \
    TensorBoardWriter

Bengt avatar Dec 06 '21 17:12 Bengt

Not using --profile hug seems to avoid the problem as well.

Bengt avatar Dec 06 '21 17:12 Bengt

Basically this config results in this behaviour:

include_trailing_comma = true
multi_line_output = 2

Avasam avatar Sep 08 '22 17:09 Avasam