Skip to content

When reformatting a triple-quote string, black fails with an INTERNAL ERROR: Black produced code that is not equivalent to the source #4288

Closed

Description

@aaribaud

Describe the bug

When reformatting a triple-quote string, black fails with an internal error.

To Reproduce

Take this code:

if __name__ == "__main__":
    """     This string...
    ... will confuse black.
    
    """
    pass

And run it with these arguments:

$ black file.py

The resulting error is:

error: cannot format blackerrdemo.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_d030my1_.log

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

Expected behavior

Black should leave the string untouched or, if it decides to reformat it, reformat it without failure.

Environment

  • Black's version: [24.3.0 (compiled: yes), 24.3.1.dev5+gc9d2635 (compiled: no)]
  • OS and Python version: [Debian Linux 12 (Bookworm)/Python 3.11.2]

Additional context

Reproduced with branch main at commit c9d2635

Activity

  1. added a commit that references this issue on Mar 23, 2024
    836acad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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