Skip to content

string_processing: Ugly reformatting of string literal with .format() method #3410

@JelleZijlstra

Description

@JelleZijlstra
% cat quash.py 
class X:
    def generate_shared_lib_init(self) -> None:
        emitter.emit_lines(
            "{",
            (
                'static PyModuleDef def = {{ PyModuleDef_HEAD_INIT, "{}", NULL, -1, NULL, NULL }};'.format(
                    shared_lib_name(self.group_name)
                )
            ),
        )
% black --preview --diff quash.py
--- quash.py	2022-12-09 03:02:23.973269 +0000
+++ quash.py	2022-12-09 03:03:57.327044 +0000
@@ -1,10 +1,7 @@
 class X:
     def generate_shared_lib_init(self) -> None:
         emitter.emit_lines(
             "{",
-            (
-                'static PyModuleDef def = {{ PyModuleDef_HEAD_INIT, "{}", NULL, -1, NULL, NULL }};'.format(
-                    shared_lib_name(self.group_name)
-                )
-            ),
+            'static PyModuleDef def = {{ PyModuleDef_HEAD_INIT, "{}", NULL, -1, NULL, NULL }};'
+            .format(shared_lib_name(self.group_name)),
         )
would reformat quash.py

All done! ✨ 🍰 ✨
1 file would be reformatted.

I like the old code better so I wouldn't want stable style to start behaving like this (ref. #3407).

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: parenthesesToo many parentheses, not enough parentheses, and so on.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