-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary parentheses from
with
statements (#2926)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Richard Si <63936253+ichard26@users.noreply.github.com>
- Loading branch information
1 parent
4d0a4b1
commit 24c708e
Showing
5 changed files
with
218 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
with (open("bla.txt")): | ||
pass | ||
|
||
with (open("bla.txt")), (open("bla.txt")): | ||
pass | ||
|
||
with (open("bla.txt") as f): | ||
pass | ||
|
||
# Remove brackets within alias expression | ||
with (open("bla.txt")) as f: | ||
pass | ||
|
||
# Remove brackets around one-line context managers | ||
with (open("bla.txt") as f, (open("x"))): | ||
pass | ||
|
||
with ((open("bla.txt")) as f, open("x")): | ||
pass | ||
|
||
with (CtxManager1() as example1, CtxManager2() as example2): | ||
... | ||
|
||
# Brackets remain when using magic comma | ||
with (CtxManager1() as example1, CtxManager2() as example2,): | ||
... | ||
|
||
# Brackets remain for multi-line context managers | ||
with (CtxManager1() as example1, CtxManager2() as example2, CtxManager2() as example2, CtxManager2() as example2, CtxManager2() as example2): | ||
... | ||
|
||
# Don't touch assignment expressions | ||
with (y := open("./test.py")) as f: | ||
pass | ||
|
||
# Deeply nested examples | ||
# N.B. Multiple brackets are only possible | ||
# around the context manager itself. | ||
# Only one brackets is allowed around the | ||
# alias expression or comma-delimited context managers. | ||
with (((open("bla.txt")))): | ||
pass | ||
|
||
with (((open("bla.txt")))), (((open("bla.txt")))): | ||
pass | ||
|
||
with (((open("bla.txt")))) as f: | ||
pass | ||
|
||
with ((((open("bla.txt")))) as f): | ||
pass | ||
|
||
with ((((CtxManager1()))) as example1, (((CtxManager2()))) as example2): | ||
... | ||
|
||
# output | ||
with open("bla.txt"): | ||
pass | ||
|
||
with open("bla.txt"), open("bla.txt"): | ||
pass | ||
|
||
with open("bla.txt") as f: | ||
pass | ||
|
||
# Remove brackets within alias expression | ||
with open("bla.txt") as f: | ||
pass | ||
|
||
# Remove brackets around one-line context managers | ||
with open("bla.txt") as f, open("x"): | ||
pass | ||
|
||
with open("bla.txt") as f, open("x"): | ||
pass | ||
|
||
with CtxManager1() as example1, CtxManager2() as example2: | ||
... | ||
|
||
# Brackets remain when using magic comma | ||
with ( | ||
CtxManager1() as example1, | ||
CtxManager2() as example2, | ||
): | ||
... | ||
|
||
# Brackets remain for multi-line context managers | ||
with ( | ||
CtxManager1() as example1, | ||
CtxManager2() as example2, | ||
CtxManager2() as example2, | ||
CtxManager2() as example2, | ||
CtxManager2() as example2, | ||
): | ||
... | ||
|
||
# Don't touch assignment expressions | ||
with (y := open("./test.py")) as f: | ||
pass | ||
|
||
# Deeply nested examples | ||
# N.B. Multiple brackets are only possible | ||
# around the context manager itself. | ||
# Only one brackets is allowed around the | ||
# alias expression or comma-delimited context managers. | ||
with open("bla.txt"): | ||
pass | ||
|
||
with open("bla.txt"), open("bla.txt"): | ||
pass | ||
|
||
with open("bla.txt") as f: | ||
pass | ||
|
||
with open("bla.txt") as f: | ||
pass | ||
|
||
with CtxManager1() as example1, CtxManager2() as example2: | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters