Skip to content

Drop redundant parenthesis in with statement #2921

@intgr

Description

@intgr

Describe the bug

Black removes redundant parenthesis in most contexts, but this does not apply to the with statement yet.

To Reproduce
Playground link

if (open("bla.txt")):
    pass

with (open("bla.txt")):
    pass

Output:

if open("bla.txt"):    # <-- parenthesis removed
    pass

with (open("bla.txt")):    # <-- parenthesis retained
    pass

Adding --target-version=py310 or --preview does not change this behavior.

Environment

  • Black's version: 22.1.0 and main branch
  • OS and Python version: Python 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: parenthesesToo many parentheses, not enough parentheses, and so on.S: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions