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

Unrecoverable exception with from ..import ccc #2152

Closed
paternal opened this issue Jul 3, 2023 · 0 comments · Fixed by #2191
Closed

Unrecoverable exception with from ..import ccc #2152

paternal opened this issue Jul 3, 2023 · 0 comments · Fixed by #2191

Comments

@paternal
Copy link

paternal commented Jul 3, 2023

Hello,
I got ERROR: Unrecoverable exception thrown when parsing ./aaa/bbb/ccc.py! This should NEVER happen.

$ python --version
Python 3.11.4
$ isort --version

                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.12.0
$ cat /etc/debian_version 
trixie/sid
$ tree
.
└── aaa
    └── bbb
        └── ccc.py

Content of the offending file:

$ cat aaa/bbb/ccc.py 
from ..import bbb

My file is valid (or I just found a Python bug):

$ python -m aaa.bbb.ccc
$

But isort fails:

$ isort .
ERROR: Unrecoverable exception thrown when parsing ./aaa/bbb/ccc.py! This should NEVER happen.
If encountered, please open an issue: https://github.com/PyCQA/isort/issues/new
Traceback (most recent call last):
  File "/home/louis/.virtualenvs/311/bin/isort", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/main.py", line 1226, in main
    for sort_attempt in attempt_iterator:
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/main.py", line 1210, in <genexpr>
    sort_imports(  # type: ignore
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/main.py", line 93, in sort_imports
    incorrectly_sorted = not api.sort_file(
                             ^^^^^^^^^^^^^^
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/api.py", line 429, in sort_file
    changed = sort_stream(
              ^^^^^^^^^^^^
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/api.py", line 210, in sort_stream
    changed = core.process(
              ^^^^^^^^^^^^^
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/core.py", line 422, in process
    parsed_content = parse.file_contents(import_section, config=config)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/louis/.virtualenvs/311/lib/python3.11/site-packages/isort/parse.py", line 522, in file_contents
    if "," in import_string.split(just_imports[-1])[-1]:
                                  ~~~~~~~~~~~~^^^^
IndexError: list index out of range

Everything works if I replace from ..import bbb with from .. import bbb (notice the space that was added/removed between .. and import).

Thanks for your work!
-- Louis

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