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

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

Closed
JelleZijlstra opened this issue Jul 9, 2023 · 1 comment · Fixed by #2184

Comments

@JelleZijlstra
Copy link

% 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.

@bp72
Copy link
Contributor

bp72 commented Oct 17, 2023

Hi! I added a small fix for this issue here: #2184
It has a failing check for the line function cyclomatic complexity, but I don't think that it's the result of this change, so I would suggest simplifying the function in a separate PR :)

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

Successfully merging a pull request may close this issue.

2 participants