Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into black23
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jan 31, 2023
2 parents 2c0b333 + 226cbf0 commit 0da89c4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
additional_dependencies: *version_check_dependencies

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort

Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- Fix an invalid quote escaping bug in f-string expressions where it produced invalid
code. Implicitly concatenated f-strings with different quotes can now be merged or
quote-normalized by changing the quotes used in expressions. (#3509)
- Fix crash on `await (yield)` when Black is compiled with mypyc (#3533)

### Configuration

Expand Down
25 changes: 13 additions & 12 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,18 +1200,19 @@ def remove_await_parens(node: Node) -> None:
# N.B. We've still removed any redundant nested brackets though :)
opening_bracket = cast(Leaf, node.children[1].children[0])
closing_bracket = cast(Leaf, node.children[1].children[-1])
bracket_contents = cast(Node, node.children[1].children[1])
if bracket_contents.type != syms.power:
ensure_visible(opening_bracket)
ensure_visible(closing_bracket)
elif (
bracket_contents.type == syms.power
and bracket_contents.children[0].type == token.AWAIT
):
ensure_visible(opening_bracket)
ensure_visible(closing_bracket)
# If we are in a nested await then recurse down.
remove_await_parens(bracket_contents)
bracket_contents = node.children[1].children[1]
if isinstance(bracket_contents, Node):
if bracket_contents.type != syms.power:
ensure_visible(opening_bracket)
ensure_visible(closing_bracket)
elif (
bracket_contents.type == syms.power
and bracket_contents.children[0].type == token.AWAIT
):
ensure_visible(opening_bracket)
ensure_visible(closing_bracket)
# If we are in a nested await then recurse down.
remove_await_parens(bracket_contents)


def _maybe_wrap_cms_in_parens(
Expand Down
7 changes: 7 additions & 0 deletions tests/data/simple_cases/remove_await_parens.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ async def main():
async def main():
await (await (await (await (await (asyncio.sleep(1))))))

async def main():
await (yield)

# output
import asyncio

Expand Down Expand Up @@ -167,3 +170,7 @@ async def main():

async def main():
await (await (await (await (await asyncio.sleep(1)))))


async def main():
await (yield)

0 comments on commit 0da89c4

Please sign in to comment.