Skip to content

with statement with type comment #3677

@15r10nk

Description

@15r10nk

Describe the bug

The following code can not be formatted

with (a,b): # type: something
    pass

when run with these arguments:

$ black example.py

The error is:

error: cannot format example.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: /tmp/blk_o04ck2zv.log

Oh no! 💥 💔 💥
1 file failed to reformat.

Environment

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

Additional context

--- src
+++ dst
@@ -5,30 +5,29 @@
         Pass(
         )  # /Pass
       items=
         withitem(
           context_expr=
-            Tuple(
+            Name(
               ctx=
                 Load(
                 )  # /Load
-              elts=
-                Name(
-                  ctx=
-                    Load(
-                    )  # /Load
-                  id=
-                    'a',  # str
-                )  # /Name
-                Name(
-                  ctx=
-                    Load(
-                    )  # /Load
-                  id=
-                    'b',  # str
-                )  # /Name
-            )  # /Tuple
+              id=
+                'a',  # str
+            )  # /Name
+          optional_vars=
+            None,  # NoneType
+        )  # /withitem
+        withitem(
+          context_expr=
+            Name(
+              ctx=
+                Load(
+                )  # /Load
+              id=
+                'b',  # str
+            )  # /Name
           optional_vars=
             None,  # NoneType
         )  # /withitem
       type_comment=
         'something',  # str

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions