Isort: ERROR: Unrecoverable exception thrown when parsing src/pyramid/predicates.py! This should NEVER happen.

Created on 29 Sep 2020  路  11Comments  路  Source: PyCQA/isort

The log from our GitHub action says to file an issue, so here it is!
https://github.com/Pylons/pyramid/runs/1180227019#step:5:11

isort==5.5.3

This issue does not occur with isort 5.4.2.

Relevant bits:

lint installed: appdirs==1.4.4,black==20.8b1,bleach==3.2.1,check-manifest==0.43,click==7.1.2,docutils==0.16,flake8==3.8.3,isort==5.5.3,mccabe==0.6.1,mypy-extensions==0.4.3,packaging==20.4,pathspec==0.8.0,pep517==0.8.2,pycodestyle==2.6.0,pyflakes==2.2.0,Pygments==2.7.1,pyparsing==2.4.7,readme-renderer==26.0,regex==2020.9.27,six==1.15.0,toml==0.10.1,typed-ast==1.4.1,typing-extensions==3.7.4.3,webencodings==0.5.1
lint run-test-pre: PYTHONHASHSEED='979047687'
lint run-test: commands[0] | flake8 src/pyramid tests setup.py
lint run-test: commands[1] | isort --check-only --df src/pyramid tests setup.py
ERROR: Unrecoverable exception thrown when parsing src/pyramid/predicates.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/runner/work/pyramid/pyramid/.tox/lint/bin/isort", line 8, in <module>
    sys.exit(main())
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/main.py", line 886, in main
    for sort_attempt in attempt_iterator:
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/main.py", line 875, in <genexpr>
    sort_imports(  # type: ignore
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/main.py", line 88, in sort_imports
    incorrectly_sorted = not api.check_file(file_name, config=config, **kwargs)
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/api.py", line 264, in check_file
    return check_stream(
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/api.py", line 203, in check_stream
    changed: bool = sort_stream(
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/api.py", line 158, in sort_stream
    changed = core.process(
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/core.py", line 326, in process
    parse.file_contents(import_section, config=config),
  File "/home/runner/work/pyramid/pyramid/.tox/lint/lib/python3.8/site-packages/isort/parse.py", line 474, in file_contents
    straight_import |= imports[placed_module][type_of_import].get(  # type: ignore
KeyError: 'STDLIB'
ERROR: InvocationError for command /home/runner/work/pyramid/pyramid/.tox/lint/bin/isort --check-only --df src/pyramid tests setup.py (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   lint: commands failed
Error: Process completed with exit code 1.

Please let me know what I can do to help troubleshoot this error. Thank you!

bug

All 11 comments

Thanks for reporting! I'm sorry this issue affected the Pyramid project, but I'm happy to see the message helped direct the error back to the right place :) Not sure what's going on here yet, but either way fixing it is a priority.

Thanks!

~Timothy

Thanks for the quick response. I'm happy to do whatever I can to help resolve the issue. Please let me know.

@stevepiercy https://github.com/Pylons/pyramid/blame/6116c6c8be01909724127b055be633c53c4782fc/pyproject.toml#L34 I can see here that no standard library section is listed, is the intention for all stdlib imports and other thirdparty imports to end up in the same section?

@timothycrosley according to this PR by @mmerickel:

group everything that isn't pyramid into one section at the top without attempting to differentiate stdlib vs third party

@stevepiercy Thanks for the information! I was able to verify that was the behaviour of isort against the config prior to the last minor release. Work done to improve error messaging for known_sections not matching in the config, accidentally introduced this regression. I have a fix open here: https://github.com/PyCQA/isort/pull/1506/files that:

  1. Resolves the issue the Pyramid project is experiencing.
  2. Adds an additional unit test to help codify the behaviour as a supported one.
  3. Includes the Pyramid project in our integration test suite so any further changes will be verified to work against the Pyramid project before they are committed.

This will make its way to the development branch in a short time. Would it be helpful for the Pyramid project for me to push out the change as a hot fix to 5.5.x minor release, or is the next planned minor release planned for October 1st soon enough for me to push it within the 5.6.0 release?

Thanks!

~Timothy

If you are okay waiting but need a solution for the immediate commit,

diff --git a/pyproject.toml b/pyproject.toml index 36187ef..0dfea71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,3 +34,4 @@ no_lines_before = "THIRDPARTY" sections = "FUTURE,THIRDPARTY,FIRSTPARTY,LOCALFOLDER" default_section = "THIRDPARTY" known_first_party = "pyramid" +known_standard_library = [" "]

Setting the known standard library to "empty" also fixes this issue in a backward and forward compatible way.

Thanks for the quick fix! We can wait for the 5.6.0 release on Oct 1. I've notified the team of the issue.

Thank you @timothycrosley !

Happy I could help! Another, relatively urgent, issue came in so I ended up pushing out a 5.5.4 hot fix release that includes the fix for this issue.

Thanks!

~Timothy

Thank you! I tried it out, and I verify that it has been fixed.

Thanks again @timothycrosley (piling on the appreciation :D)

Was this page helpful?
0 / 5 - 0 ratings