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

Error when using "fmt: off" #3028

Closed
kwsp opened this issue Apr 22, 2022 · 1 comment
Closed

Error when using "fmt: off" #3028

kwsp opened this issue Apr 22, 2022 · 1 comment
Labels
F: fmtoff fmt: off implementation T: bug Something isn't working

Comments

@kwsp
Copy link

kwsp commented Apr 22, 2022

Tested on the latest version of black from git.

To Reproduce

For example, take this code:

import cv2


frame = cv2.imread("test.jpg")

if True:
    # fmt: off
    cv2.putText(frame, f"# faces: {n}", (10, 30), cv2.FONT_HERSHEY_DUPLEX, 1, (255, 0, 0), 1, cv2.LINE_AA)

print("hello")

And run it with these arguments:

$ black file.py --target-version py39

The resulting error is:

error: cannot format black_bug.py: INTERNAL ERROR: Black 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: /var/folders/xy/7rx63bwx6c9_0n5d50q5j5xh0000gn/T/blk_tesqobdj.log

Expected behavior

Shouldn't error.

Environment

  • Black's version: black 22.3.1.dev25+g8ed3e3d (compiled: no)
  • OS and Python version: Darwin/CPython 3.9.12

Additional context

log
--- src
+++ dst
@@ -185,37 +185,37 @@
                     )  # /Name
                 )  # /Attribute
               keywords=
             )  # /Call
         )  # /Expr
+        Expr(
+          value=
+            Call(
+              args=
+                Constant(
+                  kind=
+                    None,  # NoneType
+                  value=
+                    'hello',  # str
+                )  # /Constant
+              func=
+                Name(
+                  ctx=
+                    Load(
+                    )  # /Load
+                  id=
+                    'print',  # str
+                )  # /Name
+              keywords=
+            )  # /Call
+        )  # /Expr
       orelse=
       test=
         Constant(
           kind=
             None,  # NoneType
           value=
             True,  # bool
         )  # /Constant
     )  # /If
-    Expr(
-      value=
-        Call(
-          args=
-            Constant(
-              kind=
-                None,  # NoneType
-              value=
-                'hello',  # str
-            )  # /Constant
-          func=
-            Name(
-              ctx=
-                Load(
-                )  # /Load
-              id=
-                'print',  # str
-            )  # /Name
-          keywords=
-        )  # /Call
-    )  # /Expr
   type_ignores=
 )  # /Module
\ No newline at end of file
@kwsp kwsp added the T: bug Something isn't working label Apr 22, 2022
@JelleZijlstra JelleZijlstra added the F: fmtoff fmt: off implementation label Apr 22, 2022
@JelleZijlstra
Copy link
Collaborator

Duplicate of #569 (or one of the others in F: fmtoff fmt: off implementation )

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

No branches or pull requests

2 participants