PyCQA / PyCQA/isort

Comments in group imports are moved to a single line causing line too long violation (black, flake8)

Open
#1,852 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

Hi,
this issue seems to be related to #1009 #1843.

When using isort as a pre-commit hook with black profile. My commented imports are being moved to a single line.

Commented imports are intentional because I have some work in progress but I'd still like to commit (without --no-verify)

Example:
Before:

from dj_rest_auth.views import (
    LoginView,
    LogoutView,
    # PasswordChangeView,
    # PasswordResetConfirmView,
    # PasswordResetView,
    # UserDetailsView,
)

After:

from dj_rest_auth.views import (  # PasswordChangeView,; PasswordResetConfirmView,; PasswordResetView,; UserDetailsView,
    LoginView,
    LogoutView,
)

My pre-commit hook configuration:

# isort
  - repo: https://github.com/pycqa/isort
    rev: 5.10.1
    hooks:
      - id: isort

        name: isort (python)
        args: &isort_args
          - --line-length=100
          - --profile=black
          - --combine-as
          - --lines-after-imports=2
          - --src-path=app
      - id: isort
        name: isort (cython)
        types: [ cython ]
        args: *isort_args
      - id: isort
        name: isort (pyi)
        types: [ pyi ]
        args: *isort_args

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Reproduce the issue with isort 5.10.1 using the shown Python import block and pre-commit configuration, then inspect how commented imports are handled with the black profile. Done means commented imports are not collapsed into an overlong line and the resulting output remains compatible with black and flake8.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.