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

bug formatting await (a**b) #3676

Closed
15r10nk opened this issue May 4, 2023 · 2 comments · Fixed by #3994
Closed

bug formatting await (a**b) #3676

15r10nk opened this issue May 4, 2023 · 2 comments · Fixed by #3994
Labels
C: crash Black is crashing F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working

Comments

@15r10nk
Copy link

15r10nk commented May 4, 2023

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.

@15r10nk 15r10nk added the T: bug Something isn't working label May 4, 2023
@JelleZijlstra JelleZijlstra added C: crash Black is crashing F: parentheses Too many parentheses, not enough parentheses, and so on. labels May 4, 2023
@JelleZijlstra
Copy link
Collaborator

Thanks! I suppose we get the precedence wrong and incorrectly remove the parentheses. Let us know if you find additional crashes while fuzzing.

@15r10nk
Copy link
Author

15r10nk commented May 6, 2023

I found two other issues while fuzzing, #3678 and #3677. I will stop searching for now because it seems that I find always the same issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing F: parentheses Too many parentheses, not enough parentheses, and so on. T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants