Skip to content

Preview style unnecessarily moves comment #3924

@JelleZijlstra

Description

@JelleZijlstra

The preview style moves a comment on one line of an implicitly concatenated string to a different line.

$ python -m black --version
python -m black, 23.9.1 (compiled: yes)
Python (CPython) 3.9.14
$ python -m black --diff --preview movecomment.py 
--- movecomment.py      2023-10-06 01:40:10.153647+00:00
+++ movecomment.py      2023-10-06 01:40:41.077230+00:00
@@ -1,7 +1,7 @@
 xxxxxxx.xxfx(
-    f"xxxx_xxxxxxxx: "  # xxxxxxx
+    "xxxx_xxxxxxxx: "
     f"xxxxx={xxxx_xxxxxxxx.xxxxx}, "
     f"_xxx_xxxxxx={xxxx_xxxxxxxx._xxx_xxxxxx}, "
     f"xxx_xxxxxx={xxxx_xxxxxxxx.xxx_xxxxxx}, "
-    f"xxx_xxxxx={xxxx_xxxxxxxx.xxx_xxxxx}"
+    f"xxx_xxxxx={xxxx_xxxxxxxx.xxx_xxxxx}"  # xxxxxxx
 )
would reformat movecomment.py

All done! ✨ 🍰 ✨
1 file would be reformatted.
$ cat movecomment.py 
xxxxxxx.xxfx(
    f"xxxx_xxxxxxxx: "  # xxxxxxx
    f"xxxxx={xxxx_xxxxxxxx.xxxxx}, "
    f"_xxx_xxxxxx={xxxx_xxxxxxxx._xxx_xxxxxx}, "
    f"xxx_xxxxxx={xxxx_xxxxxxxx.xxx_xxxxxx}, "
    f"xxx_xxxxx={xxxx_xxxxxxxx.xxx_xxxxx}"
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions