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

[Infinite loop] When adding required import to file with # isort: off as first line #4575

Closed
bendoerry opened this issue May 22, 2023 · 0 comments · Fixed by #4581
Closed
Assignees
Labels
bug Something isn't working isort Related to import sorting

Comments

@bendoerry
Copy link
Contributor

Summary

If I add required imports to a python file where the very first line is # isort: off ruff will raise an error and add the required import multiple times. This does not happen if the # isort: off directive is not the first line

Ruff Version:

0.0.269

Ruff Config:

[isort]
required-imports = [
  "from __future__ import annotations",
]

Ruff Command:

ruff check --fix --select I002 unsorted.py

isort: off directive on first line

Python File: unsorted.py

# isort: off
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps

Ruff Output

error: Failed to converge after 100 iterations.

This indicates a bug in `ruff`. If you could open an issue at:

    https://github.com/charliermarsh/ruff/issues/new?title=%5BInfinite%20loop%5D

...quoting the contents of `unsorted.py`, the rule codes I002, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

unsorted.py:1:1: I002 Missing required import: `from __future__ import annotations`
Found 101 errors (100 fixed, 1 remaining).

Modified Python File

# isort: off
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from __future__ import annotations
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps

Other comment as first line

Python File: unsorted.py

# No Issue
# isort: off
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps

Ruff Output

Found 1 error (1 fixed, 0 remaining).

Modified Python File

# No Issue
from __future__ import annotations
# isort: off
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps

Ideally I would have an extra line between the future import and the # isort: off comment.

Blank first line

Python File: unsorted.py

# isort: off
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps

Ruff Output

Found 1 error (1 fixed, 0 remaining).

Modified Python File

from __future__ import annotations

# isort: off
from json import dumps
from base64 import b64encode

# isort: on
from collections import defaultdict
from functools import wraps
@charliermarsh charliermarsh added bug Something isn't working isort Related to import sorting labels May 22, 2023
@charliermarsh charliermarsh self-assigned this May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working isort Related to import sorting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants