Skip to content

I001: Support for magic trailing commas #1200

@Jackenmen

Description

@Jackenmen

Black auto-explodes imports, collections, function calls, etc. when they contain a trailing comma:
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#the-magic-trailing-comma

This means that even though this would fit into one line:

from seven_dwwarfs import (
    Grumpy,
    Happy,
    Sleepy,
    Bashful,
    Sneezy,
    Dopey,
    Doc,
)

Black will NOT convert it into this:

from seven_dwwarfs import Grumpy, Happy, Sleepy, Bashful, Sneezy, Dopey, Doc

As long as the import list contains a trailing comma.

Ruff currently does not have the magic trailing comma handling as far as I can tell and will collapse the import list if it can fit within the line length limit.

See relevant fixed (but not released) issue in isort: PyCQA/isort#1683

Metadata

Metadata

Assignees

No one assigned

    Labels

    isortRelated to import sorting

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions