isort icon indicating copy to clipboard operation
isort copied to clipboard

Long imports and noqa

Open matan1008 opened this issue 1 year ago • 7 comments

Hola, I have an import from the following format:

from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd  # noqa: E402
from aaaaaaa import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, fffffffffffffffffffff  # noqa: E402

When running isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df it prints:

-from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd  # noqa: E402
-from aaaaaaa import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, fffffffffffffffffffff  # noqa: E402
+from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd, eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, \
+    fffffffffffffffffffff  # noqa: E402

Running isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df again, it prints:

-from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd, eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, \
-    fffffffffffffffffffff  # noqa: E402
+from aaaaaaa import fffffffffffffffffffff  # noqa: E402
+from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd, eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

Besides of the strange behavior that yields two different formattings, the second one missing the noqa.

matan1008 avatar Sep 13 '24 16:09 matan1008

I'm not able to reproduce locally using isort 5.13.2.

I recommend closing this issue. Thanks!

kurtmckee avatar Jan 06 '25 19:01 kurtmckee

@DanielNoord This issue is not reproducible. I recommend closing this issue.

kurtmckee avatar Jan 09 '25 14:01 kurtmckee

Can I help reproducing it? It happens to me on two different ubuntu computers I also tested it inside a docker to make sure it can be reproduced

Image

matan1008 avatar Jan 10 '25 14:01 matan1008

I see in your diff output that the file you're testing is larger than just the two lines that you originally posted.

Please confirm that you can reproduce using these steps:

cd $HOME
mkdir whatever-bogus
cd whatever-bogus
git init

# Copy a.py to the whatever-bogus directory

isort --version
isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df
isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df

If so, please provide the full a.py file here. Thanks!

(whatever-bogus isn't an important name, I'm just suggesting to use a temp directory and prevent isort from searching any higher in the filesystem by making it a git repository.)

kurtmckee avatar Jan 10 '25 14:01 kurtmckee

Image

matan1008 avatar Jan 11 '25 09:01 matan1008

@DanielNoord I'm able to reproduce this now. The issue is valid and needs to be reopened -- isort has non-idempotent behavior.

@matan1008 You were changing the file between --check-only runs, as shown by the changing timestamp of the file in the diff output, but you didn't document this. When reporting issues to projects in the future, please document all of the steps you're taking. Thanks! 👍

For others' benefit, the full file is:

from aaaaaaa import bbbbbbbbbbbbbbbbb, ccccccccccccccccccc, dddddddddddddddd  # noqa: E402
from aaaaaaa import eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee, fffffffffffffffffffff  # noqa: E402


print(fffffffffffffffffffff)
print(dddddddddddddddd)

and the full steps to reproduce are:

mkdir whatever-bogus
cd whatever-bogus
git init

# Copy a.py to this directory

# Show the diff, then run isort
isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df
isort . -m HANGING_INDENT -l 120 --combine-as

# Demonstrate non-idempotent behavior
isort . -m HANGING_INDENT -l 120 --check-only --combine-as --df

kurtmckee avatar Jan 11 '25 14:01 kurtmckee

Could you reopen the issue (and perhaps fix it)?

matan1008 avatar Sep 11 '25 14:09 matan1008