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

noqa isn't well respected #2270

Closed
barseghyanartur opened this issue Jun 9, 2024 · 2 comments
Closed

noqa isn't well respected #2270

barseghyanartur opened this issue Jun 9, 2024 · 2 comments

Comments

@barseghyanartur
Copy link

Filename: example.py

from typing import Any, Dict

from django.conf import settings
from django.contrib.auth.models import (  # noqa
    Group,  # noqa
    User,  # noqa
)  # noqa
from django.utils import timezone
from django.utils.text import slugify

Filename: pyproject.toml

[tool.isort]
profile = "black"
combine_as_imports = true
multi_line_output = 3
force_single_line = false
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 80
honor_noqa = true
known_first_party = [
    "address",
    "article",
    "config",
    "data",
    "fake_address",
    "fake_band",
]
known_third_party = ["fake"]
skip = ["wsgi.py", "builddocs/"]

I obviously don't want isort to touch any line with noqa present. But isort does make changes. It forces it into from django.contrib.auth.models import Group, User (which normally would be good, but I want it my way in this case for a reason).

At best, it moves my entire block with pragma comments as the very last import statement. But that's also not what I want. I want my noqa imports to remain in place where they are and be untouched.

Is there a way to achieve this? I had to disable isort for now, but I would rather not do that as a long term solution.

@kurtmckee
Copy link
Contributor

I'm not able to reproduce with isort (main branch).

I created a new directory, created the two files you specified, then ran:

$ isort --check --diff example.py
ERROR: /home/kurt/dev/pr-isort/tmp/example.py Imports are incorrectly sorted and/or formatted.
--- /home/kurt/dev/pr-isort/tmp/example.py:before       2025-01-06 18:36:29.048041
+++ /home/kurt/dev/pr-isort/tmp/example.py:after        2025-01-06 18:38:43.418362
@@ -1,9 +1,10 @@
 from typing import Any, Dict
 
 from django.conf import settings
+from django.utils import timezone
+from django.utils.text import slugify
+
 from django.contrib.auth.models import (  # noqa
     Group,  # noqa
     User,  # noqa
 )  # noqa
-from django.utils import timezone
-from django.utils.text import slugify

Please double-check that you don't have another isort config file, or an old version of isort.

If this is resolved, please close this issue. Thanks!

@kurtmckee
Copy link
Contributor

@DanielNoord This issue isn't reproducible on main. I recommend closing this issue.

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