Skip to content

Lines with power operator ** with simple operands are wrapped too early #3889

@andersk

Description

@andersk

Describe the bug

Black miscomputes the horizontal space required for lines containing the power operator ** with simple operands, and rewraps them much earlier than the expected 88-character line length. Perhaps that computation wasn’t adjusted for #538/#2726.

To Reproduce

Run Black with no arguments on this code (playground link):

x = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
y = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1

Black leaves the first line unaffected, but unexpectedly wraps the second vertically, even though its horizontal layout is only 56 characters long.

x = 1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1**1
y = (
    1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
    ** 1
)

Expected behavior

Both lines should be unchanged.

Environment

  • Black's version: 23.9.1
  • OS and Python version: Linux/Python 3.10.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions