You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a blank __init__.py with a newline in it, with float_to_top = true in my .isort.cfg after upgrading from 4.x.
The __init__.py should not have the newline, but I had removed a few imports and left the newline in the file. Unfortunately, the isort error made tracking down which file was causing the issue difficult, since I was running isort . on a large project.
Encountered with 0.5.2, 0.5.4, & 0.5.5.
A minimal example:
$ echo "\n" > example.py
$ .venv/bin/isort --float-to-top example.py
Traceback (most recent call last):
File ".venv/bin/isort", line 10, in <module>
sys.exit(main())
File ".venv/lib/python3.8/site-packages/isort/main.py", line 876, in main
for sort_attempt in attempt_iterator:
File ".venv/lib/python3.8/site-packages/isort/main.py", line 865, in <genexpr>
sort_imports( # type: ignore
File ".venv/lib/python3.8/site-packages/isort/main.py", line 93, in sort_imports
incorrectly_sorted = not api.sort_file(
File ".venv/lib/python3.8/site-packages/isort/api.py", line 321, in sort_file
changed = sort_stream(
File ".venv/lib/python3.8/site-packages/isort/api.py", line 158, in sort_stream
changed = core.process(
File ".venv/lib/python3.8/site-packages/isort/core.py", line 89, in process
while current[-1] == "\n":
IndexError: string index out of range
Removing the blank line in example.py resolves the issue. Also not an issue with --float-to-top not used.
Ideally this file would not cause any issue when --float-to-top is used. It may also be nice if an indication is given as to what file is being processed when internal errors occur, to allow manual review of that file for Python syntax errors.
The text was updated successfully, but these errors were encountered:
I had a blank
__init__.py
with a newline in it, withfloat_to_top = true
in my .isort.cfg after upgrading from 4.x.The
__init__.py
should not have the newline, but I had removed a few imports and left the newline in the file. Unfortunately, the isort error made tracking down which file was causing the issue difficult, since I was runningisort .
on a large project.Encountered with 0.5.2, 0.5.4, & 0.5.5.
A minimal example:
Removing the blank line in example.py resolves the issue. Also not an issue with --float-to-top not used.
Ideally this file would not cause any issue when --float-to-top is used. It may also be nice if an indication is given as to what file is being processed when internal errors occur, to allow manual review of that file for Python syntax errors.
The text was updated successfully, but these errors were encountered: