Skip to content

Crash with line-length 6 and multi-line docstring #3427

@JelleZijlstra

Description

@JelleZijlstra
def x():
    """first line----------------------------------------------------------------------

    second line----------------------------------------------------------------------"""

Crashes with Black 22.12.0:

% black --preview --diff tests/data/preview/docstring_preview.py -l 6
error: cannot format tests/data/preview/docstring_preview.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/3b/k964cnv10097wzj3h7w07fww0000gp/T/blk_la0pkiyv.log

Oh no! 💥 💔 💥
1 file would fail to reformat.
% cat /var/folders/3b/k964cnv10097wzj3h7w07fww0000gp/T/blk_la0pkiyv.log

Mode(target_versions={<TargetVersion.PY38: 8>, <TargetVersion.PY37: 7>}, line_length=6, string_normalization=True, is_pyi=False, is_ipynb=False, skip_source_first_line=False, magic_trailing_comma=True, experimental_string_processing=False, python_cell_magics=set(), preview=True)
--- source
+++ first pass
@@ -1,4 +1,6 @@
 def x():
     """first line----------------------------------------------------------------------
 
-    second line----------------------------------------------------------------------"""
+    second line----------------------------------------------------------------------
+    
+    """
--- first pass
+++ second pass
@@ -1,6 +1,7 @@
 def x():
     """first line----------------------------------------------------------------------
 
     second line----------------------------------------------------------------------
+
     
     """

I guess this stops crashing at line-length 7 because then """ (one level of indent plus trailing quotes) fits in a line.

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: docstringsHow we format docstringsT: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions