Skip to content

isort introduces SyntaxError with multiline "from a import b as c" plus a comment ending in a parenthesis #2154

@JelleZijlstra

Description

@JelleZijlstra
% cat frimp.py 
from a import (
    b as c,  # comment that is long enough that this import doesn't fit in one line (parens)
)
% isort --diff frimp.py --profile=black
--- /Users/jelle/py/tmp/frimp.py:before	2023-07-09 09:06:19.191799
+++ /Users/jelle/py/tmp/frimp.py:after	2023-07-09 09:08:40.508309
@@ -1,3 +1,3 @@
 from a import (
-    b as c,  # comment that is long enough that this import doesn't fit in one line (parens)
+    b as c,)  # comment that is long enough that this import doesn't fit in one line (parens
 )

It incorrectly moves the parenthesis at the end of the comment into the code.

Reproduced on isort 5.12.0. Came up in PyCQA/flake8-pyi#411.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions