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

INTERNAL ERROR: Black produced code that is not equivalent to the source #4481

Open
ryank231231 opened this issue Oct 14, 2024 · 2 comments
Open
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working

Comments

@ryank231231
Copy link

Describe the bug

Formatting the code snippet below produces an internal error.

To Reproduce

Format the following code snippet:

foo(
    bar()    # fmt: skip
  + bar()    # fmt: skip
)

The resulting error is:

INTERNAL ERROR: Black 24.10.1.dev3+g9995bff on Python (CPython) 3.12.5 produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_vu09qp1g.log

Log:

INTERNAL ERROR: Black 24.10.1.dev3+g9995bff on Python (CPython) 3.12.5 produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_vu09qp1g.log

--- src
+++ dst
@@ -2,41 +2,22 @@
     body=
     Expr(
         value=
         Call(
             args=
-            BinOp(
-                left=
-                Call(
-                    args=
-                    func=
-                    Name(
-                        ctx=
-                        Load(
-                        )  # /Load
-                        id=
-                        'bar',  # str
-                    )  # /Name
-                    keywords=
-                )  # /Call
-                op=
-                Add(
-                )  # /Add
-                right=
-                Call(
-                    args=
-                    func=
-                    Name(
-                        ctx=
-                        Load(
-                        )  # /Load
-                        id=
-                        'bar',  # str
-                    )  # /Name
-                    keywords=
-                )  # /Call
-            )  # /BinOp
+            Call(
+                args=
+                func=
+                Name(
+                    ctx=
+                    Load(
+                    )  # /Load
+                    id=
+                    'bar',  # str
+                )  # /Name
+                keywords=
+            )  # /Call
             func=
             Name(
                 ctx=
                 Load(
                 )  # /Load

Expected behavior

The lines should be left untouched.

Environment

  • Black's version: Black 24.10.1.dev3+g9995bff
  • OS and Python version: Python (CPython) 3.12.5

Can also be reproduced on https://black.vercel.app/?version=main&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ADHAGZdAD2IimZxl1N_WlkOE2WKO8q04xFLHliTY02DINaThb5NmXp3LURBIVoPx1hVWZbZyQHzS7z4xwAjKn-Mq7mHuHTZTmuDTTSwvMjOpdZEDkCdYF5Qlw2K-7fLc9LT6VrsBXcNyBZpZgAAANIVr-TpMphLAAGCAcgBAABg5HYfscRn-wIAAAAABFla .

@ryank231231 ryank231231 added the T: bug Something isn't working label Oct 14, 2024
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 14, 2024

Black 24.10.1.dev3+g9995bff

Hmm, we should ban running on 3.12.5 as of #4447 , because an upstream memory safety issue can cause AST safety checks to fail. Do you have a local repro, if so, could you figure out why the check against 3.12.5 isn't working for you?

Looks like the issue is unrelated to that, though. Probably a duplicate of #3608

@hauntsaninja hauntsaninja added the F: fmtskip fmt: skip implementation label Oct 14, 2024
@ryank231231
Copy link
Author

Hmm, we should ban running on 3.12.5 as of #4447, because an upstream memory safety issue can cause AST safety checks to fail.

Just to clarify, Python 3.12.5 was being used in the playground, and I was able to reproduce the same issue locally as well. My local setup uses Black 24.10.0 and CPython 3.11.2.

Do you have a local repro? If so, could you figure out why the check against 3.12.5 isn't working for you?

Yes, I was able to reproduce the issue locally with Black 24.10.0 and CPython 3.11.2. The same internal error occurs with the provided code snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtskip fmt: skip implementation T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants