Skip to content

Black moves same-block trailing comment inside expression wrapped with parentheses  #3741

@cnpryer

Description

@cnpryer

Describe the bug

black formats the following code improperly handling # Trailing same-block.

x = 1
# Leading comment
del (
    # First inner own-line
    x  # Trailing comment same-line
    # Trailing comment own-line last inner
)  # Trailing same-block
# Trailing own-line

Result

@@ -4,5 +4,6 @@ del (
     # First inner own-line
     x  # Trailing comment same-line
     # Trailing comment own-line last inner
-)  # Trailing same-block
-# Trailing own-line
\ No newline at end of file
+    # Trailing same-block
+)
+# Trailing own-line

Environment

black, 23.3.0 (compiled: yes)
Python (CPython) 3.11.3

MacOS 13.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: commentsThe syntactic kind. Not in the language grammar, always on our minds. Best bugs.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions