Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop redundant parenthesis in with statement #2921

Closed
intgr opened this issue Mar 14, 2022 · 3 comments · Fixed by #2926
Closed

Drop redundant parenthesis in with statement #2921

intgr opened this issue Mar 14, 2022 · 3 comments · Fixed by #2926
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: bug Something isn't working

Comments

@intgr
Copy link

intgr commented Mar 14, 2022

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
@intgr intgr added the T: bug Something isn't working label Mar 14, 2022
@JelleZijlstra JelleZijlstra added F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented labels Mar 14, 2022
@JelleZijlstra
Copy link
Collaborator

Yes, we should remove these. There are a bunch of other contexts where we leave redundant parens around.

@intgr
Copy link
Author

intgr commented Mar 14, 2022

Some additional test cases involving with:

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

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

with (open("bla.txt") as f, open("x")):
    pass

with ((open("bla.txt")) as f, open("x")):
    pass

@intgr
Copy link
Author

intgr commented Apr 3, 2022

Thanks @jpy-git! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants