Skip to content

Consider not wrapping a single import when the line is too long #3324

@yilei

Description

@yilei

Describe the style change

When an import line is too long, and it only has a single imported symbol, it's more readable to NOT wrap the line.

Examples in the current Black style

from company.organization.products.my_awesome_learning_system.backend.handlers import (
    register,
)
from company.organization.products.my_awesome_learning_system.common import logging
from company.organization.products.my_awesome_learning_system.utils import (
    authentication,
)

Desired style

from company.organization.products.my_awesome_learning_system.backend.handlers import register
from company.organization.products.my_awesome_learning_system.common import logging
from company.organization.products.my_awesome_learning_system.utils import authentication

Additional context

The current behavior works very well in the majority cases. If the import line has more than one imports, it should continue wrapping them:

from company.organization.products.my_awesome_learning_system.backend.handlers import (
    enroll,
    login,
    register,
)

But for code bases that follow the Google Python Style Guide to only import modules/packages, never individual functions/classes from a module (it won't import multiple symbols in the same line, except from typing), Black can make the imports very awkward.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: styleWhat do we want Blackened code to look like?

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions