Skip to content

Reject non-positive --line-length values instead of silently accepting them #5663

Closed

Description

@Aathi-27

Black accepts --line-length 0 or --line-length -1 without an error. A negative line-length in pyproject.toml is accepted too. It then formats valid code into extremely narrow output and exits successfully.

For example:

total = price * quantity * (1 + tax_rate)

Run:
black --line-length -1 example.py

The result is still valid Python, so this isn't source corruption. But the docs don't describe a meaning for non-positive line lengths. Would it make sense to reject them with a usage error?

I have a patch using click.IntRange(min=1) for the CLI option, which also validates pyproject.toml values, plus regression tests. The programmatic black.Mode API stays unchanged. This follows the input-validation approach in #5211.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions