multi_line_output=1 with include_trailing_comma leaves a dangling comma on a single import
Maintainers usually reply within 2 days
@beduldul is already working on this.
Since Oct 27, 2026.
Assessment
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 15/100
Research direction
The issue points to isort/wrap_modes.py and the existing test_include_trailing_comma test. Read vertical() and run that test to see how the single-import case differs from the four-import case it currently covers. Done means a single import formats validly with and without include_trailing_comma, and stays unchanged on a second run.
Written by the indexing model from the issue text.
Description
With multi_line_output=1 (VERTICAL), force_grid_wrap=1 and include_trailing_comma=True, a single-name from-import is rewritten into something that is not valid Python:
>>> import isort
>>> isort.code("from mymod import bb\n", multi_line_output=1, force_grid_wrap=1,
... include_trailing_comma=True, use_parentheses=True, line_length=40)
'from mymod import (bb,\n ,)\n'
That raises SyntaxError. The other eleven wrap modes all handle the single-import case, so it is specific to VERTICAL.
In isort/wrap_modes.py, vertical() pops the first import, appends "," to it, then joins the remaining imports and appends _comma_maybe before the closing parenthesis. With one import the joined remainder is empty, so the trailing comma ends up after the continuation indent instead of right after the name.
Expected, matching what GRID and HANGING_INDENT_WITH_PARENTHESES already produce for the same input:
'from mymod import (bb,)\n'
and with include_trailing_comma=False:
'from mymod import (bb)\n'
Both are stable across a second run. The existing test_include_trailing_comma only exercises VERTICAL with four imports, which is why this slipped through.
I have a fix with a regression test and will open a pull request.
- Dominant language
- Python
- Stars
- 7k
- Forks
- 838
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 19
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyCQA/isort
-
separate_packages splits imports from the same explicitly configured packagePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
force_sort_within_sections does not sort lazy imports by module namePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
length_sort with native sort order puts a longer import firstPossibly taken @simpleqt claimed this 24 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
PyCQA/isort#2698 · 2 comments ·
Maintainers usually reply within 2 days
-
Cache compiled known-module patterns across Config instancesPossibly taken @Yin123-ybh claimed this 2 days ago. Open
Difficulty 3/5 Half a day Newbie friendliness 30/100
PyCQA/isort#2805 · 1 comment ·
Maintainers usually reply within 2 days
-
add_imports re-adds the import on every run when the file contains an `# isort: off` block (not idempotent)Possibly taken @Tanvi-007 claimed this 6 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 72/100
PyCQA/isort#2799 · 2 comments ·
Maintainers usually reply within 2 days
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
intersystems/ipm#1338 ·
Maintainers usually reply within 1 day
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionOpenv1
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
TigreGotico/text2spoken#626 ·
Maintainers usually reply within 1 day