-
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.
Wrap multiple context managers in parentheses when targeting Python 3…
….9+ (#3489)
- Loading branch information
Showing
11 changed files
with
416 additions
and
21 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
35 changes: 35 additions & 0 deletions
35
tests/data/preview_context_managers/auto_detect/features_3_10.py
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,35 @@ | ||
# This file uses pattern matching introduced in Python 3.10. | ||
|
||
|
||
match http_code: | ||
case 404: | ||
print("Not found") | ||
|
||
|
||
with \ | ||
make_context_manager1() as cm1, \ | ||
make_context_manager2() as cm2, \ | ||
make_context_manager3() as cm3, \ | ||
make_context_manager4() as cm4 \ | ||
: | ||
pass | ||
|
||
|
||
# output | ||
|
||
|
||
# This file uses pattern matching introduced in Python 3.10. | ||
|
||
|
||
match http_code: | ||
case 404: | ||
print("Not found") | ||
|
||
|
||
with ( | ||
make_context_manager1() as cm1, | ||
make_context_manager2() as cm2, | ||
make_context_manager3() as cm3, | ||
make_context_manager4() as cm4, | ||
): | ||
pass |
37 changes: 37 additions & 0 deletions
37
tests/data/preview_context_managers/auto_detect/features_3_11.py
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,37 @@ | ||
# This file uses except* clause in Python 3.11. | ||
|
||
|
||
try: | ||
some_call() | ||
except* Error as e: | ||
pass | ||
|
||
|
||
with \ | ||
make_context_manager1() as cm1, \ | ||
make_context_manager2() as cm2, \ | ||
make_context_manager3() as cm3, \ | ||
make_context_manager4() as cm4 \ | ||
: | ||
pass | ||
|
||
|
||
# output | ||
|
||
|
||
# This file uses except* clause in Python 3.11. | ||
|
||
|
||
try: | ||
some_call() | ||
except* Error as e: | ||
pass | ||
|
||
|
||
with ( | ||
make_context_manager1() as cm1, | ||
make_context_manager2() as cm2, | ||
make_context_manager3() as cm3, | ||
make_context_manager4() as cm4, | ||
): | ||
pass |
30 changes: 30 additions & 0 deletions
30
tests/data/preview_context_managers/auto_detect/features_3_8.py
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,30 @@ | ||
# This file doesn't use any Python 3.9+ only grammars. | ||
|
||
|
||
# Make sure parens around a single context manager don't get autodetected as | ||
# Python 3.9+. | ||
with (a): | ||
pass | ||
|
||
|
||
with \ | ||
make_context_manager1() as cm1, \ | ||
make_context_manager2() as cm2, \ | ||
make_context_manager3() as cm3, \ | ||
make_context_manager4() as cm4 \ | ||
: | ||
pass | ||
|
||
|
||
# output | ||
# This file doesn't use any Python 3.9+ only grammars. | ||
|
||
|
||
# Make sure parens around a single context manager don't get autodetected as | ||
# Python 3.9+. | ||
with a: | ||
pass | ||
|
||
|
||
with make_context_manager1() as cm1, make_context_manager2() as cm2, make_context_manager3() as cm3, make_context_manager4() as cm4: | ||
pass |
Oops, something went wrong.