Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long imports and noqa #2291

Closed
matan1008 opened this issue Sep 13, 2024 · 6 comments
Closed

Long imports and noqa #2291

matan1008 opened this issue Sep 13, 2024 · 6 comments

Comments

@matan1008
Copy link

matan1008 commented Sep 13, 2024

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.

@kurtmckee
Copy link
Contributor

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

I recommend closing this issue. Thanks!

@kurtmckee
Copy link
Contributor

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

@matan1008
Copy link
Author

matan1008 commented Jan 10, 2025

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

@kurtmckee
Copy link
Contributor

kurtmckee commented Jan 10, 2025

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.)

@matan1008
Copy link
Author

Image

@kurtmckee
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants