multi_line_output=1 with include_trailing_comma leaves a dangling comma on a single import

Open
#2,752 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@beduldul is already working on this.

Since Oct 27, 2026.

  • #2753 by @beduldul — open
  • #2807 by @Burakceliks — open

Assessment

Difficulty
1/5
Estimated time
1-3 hours
Newbie friendliness
15/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
tooling

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyCQA/isort

All issues in PyCQA/isort

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.