]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Fix unsafe cast in linegen.py w/ await yield handling (#3533)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 31 Jan 2023 02:53:14 +0000 (18:53 -0800)
committerGitHub <noreply@github.com>
Tue, 31 Jan 2023 02:53:14 +0000 (21:53 -0500)
Fixes #3532.

CHANGES.md
src/black/linegen.py
tests/data/preview/remove_await_parens.py

index 2acb31d6ac49d14a0dd6b156b295efc4836a6582..8c6a4f40166b7a93757ee095471c05261ffdcaaa 100644 (file)
@@ -42,6 +42,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
 
index bfc28ca006ccc44d72185a2cd355c7e958d31de6..9894a39c95f7c6b5f127b0b0e65d284959beb8f2 100644 (file)
@@ -1223,18 +1223,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(
index 571210a2d80c7e5697596195b8303909e6e979d3..8c7223d2f3900b7a6e0778665464f9df272a425c 100644 (file)
@@ -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
 
@@ -167,3 +170,7 @@ async def main():
 
 async def main():
     await (await (await (await (await asyncio.sleep(1)))))
+
+
+async def main():
+    await (yield)