Skip to content

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

Closed

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.

Activity

  1. JelleZijlstra commented on Dec 10, 2022

    @JelleZijlstra
    CollaboratorAuthor

    Actually doesn't need long lines, this crashes in the same way with --preview -l 6:

    def f():
        """
        x
        """
  2. changed the title [-]Crash with line-length 6 and long line in docstring[/-] [+]Crash with line-length 6 and multi-line docstring[/+] on Dec 10, 2022
  3. added
    C: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.
    on Dec 19, 2022
  4. JelleZijlstra commented on Dec 19, 2022

    @JelleZijlstra
    CollaboratorAuthor

    This is fixed in 23.1a1, probably by d48f8ed (which I should put in a separate PR).

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

    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