Skip to content

Formatter: Add parentheses around too long strings #6059

@konstin

Description

@konstin

The formatter currently never adds parentheses around strings in the right hand side of an assignment. Black does add them if they help to match the line limit, otherwise it doesn't.

Input and identical ruff formatted output:

DEFAULT_FILE_STORAGE_DEPRECATED_MSG = "The DEFAULT_FILE_STORAGE setting is deprecated. Use STORAGES instead."
DEFAULT_FILE_STORAGE_DEPRECATED_MSG = "The DEFAULT_FILE_STORAGE setting is deprecated. Use STORAGES instead. This makes it so long that parentheses don't help"

Black formatted output:

DEFAULT_FILE_STORAGE_DEPRECATED_MSG = (
    "The DEFAULT_FILE_STORAGE setting is deprecated. Use STORAGES instead."
)
DEFAULT_FILE_STORAGE_DEPRECATED_MSG = "The DEFAULT_FILE_STORAGE setting is deprecated. Use STORAGES instead. This makes it so long that parentheses don't help"

Metadata

Metadata

Assignees

No one assigned

    Labels

    formatterRelated to the formatter

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions