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

Stop parenthesizing context managers on Python 3.9 #4488

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Fix formatting cells in IPython notebooks with magic methods and starting or trailing
empty lines (#4484)
- Stop parenthesizing context managers on Python 3.9. Python 3.10+ is unaffected.
(#4488)

### Preview style

Expand Down
1 change: 0 additions & 1 deletion src/black/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class Feature(Enum):
Feature.POS_ONLY_ARGUMENTS,
Feature.UNPACKING_ON_FLOW,
Feature.ANN_ASSIGN_EXTENDED_RHS,
Feature.PARENTHESIZED_CONTEXT_MANAGERS,
},
TargetVersion.PY310: {
Feature.F_STRINGS,
Expand Down
23 changes: 22 additions & 1 deletion tests/data/cases/python39.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ def f():
def f():
...

with long_context_manager_name1(), long_context_manager_name2(), long_context_manager_name3():
...

with (
long_context_manager_name1(),
long_context_manager_name2(),
long_context_manager_name3(),
):
...

# output

@relaxed_decorator[0]
Expand All @@ -25,4 +35,15 @@ def f(): ...
@extremely_long_variable_name_that_doesnt_fit := complex.expression(
with_long="arguments_value_that_wont_fit_at_the_end_of_the_line"
)
def f(): ...
def f(): ...


with long_context_manager_name1(), long_context_manager_name2(), long_context_manager_name3():
...

with (
long_context_manager_name1(),
long_context_manager_name2(),
long_context_manager_name3(),
):
...