Skip to content

bug formatting await (a**b) #3676

@15r10nk

Description

@15r10nk

Describe the bug

black converts await (a**b) into await a ** b (if run with --fast)

To Reproduce

async def name_5():
    await (name_1 ** name_4)

And run it with these arguments:

$ black file.py

The resulting error is:

cannot format file.py: INTERNAL ERROR: ...

Expected behavior

black should preserve the braces and be able to format the file

Environment

python -m black, 23.3.1.dev10+geb32729 (compiled: no)
Python (CPython) 3.11.3

Additional context

error log:

--- src
+++ dst
@@ -14,34 +14,34 @@
             None,  # NoneType
         )  # /arguments
       body=
         Expr(
           value=
-            Await(
-              value=
-                BinOp(
-                  left=
+            BinOp(
+              left=
+                Await(
+                  value=
                     Name(
                       ctx=
                         Load(
                         )  # /Load
                       id=
                         'name_1',  # str
                     )  # /Name
-                  op=
-                    Pow(
-                    )  # /Pow
-                  right=
-                    Name(
-                      ctx=
-                        Load(
-                        )  # /Load
-                      id=
-                        'name_4',  # str
-                    )  # /Name
-                )  # /BinOp
-            )  # /Await
+                )  # /Await
+              op=
+                Pow(
+                )  # /Pow
+              right=
+                Name(
+                  ctx=
+                    Load(
+                    )  # /Load
+                  id=
+                    'name_4',  # str
+                )  # /Name
+            )  # /BinOp
         )  # /Expr
       decorator_list=
       name=
         'name_5',  # str
       returns=

For context:
I currently write a generator wich generates random python code. This is still work in progress, but finding bugs in black shows me that I am on the right track.
I will provide a script similar to scripts/fuzz.py as soon as it is ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: crashBlack is crashingF: parenthesesToo many parentheses, not enough parentheses, and so on.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions