Black: Docstrings reformatted to be too long

Created on 26 Aug 2020  路  5Comments  路  Source: psf/black

Describe the bug When there's a docstring that's near the max line length with the """ on the next line, the new version of Black moves the """ to the first line, making the line too long.

To Reproduce Steps to reproduce the behavior:

  1. Create a file with this content:

    def my_func():
            """Remove punctuation and return cleaned string plus its length in tokens.
            """
            pass
    
  2. Reformat it

  3. Note that it now has the docstring on one line and that that line has 82 chars:

    def my_func():
            """Remove punctuation and return cleaned string plus its length in tokens."""
            pass
    

Expected behavior

The docstring shouldn't get wrapped.

Environment (please complete the following information):

  • Version: [e.g. master] 20.8b1

  • OS and Python version:
    Linux/Python 3.8.2

Does this bug also happen on master? To answer this, you have two options:

Yes: https://black.now.sh/?version=master&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AC3AIldAD2IimZxl1N_WlbvK5V-ga8lyrVzgK48mW1g5y7ZvjbGhEN7nG-8hLA9oQ3I4FUxivNyD3Gy0_4fbH0Mg7-k28ZpTZzLozFMvMFSuDJT_0ZQmFpNZw6AAvoHjtKEQjGQksHXW1WBInIzl_HhTgRlCs-04wcVCEBY4OInuM5XhKBPO4ZIAzTqLcpeAAAAADHge2pSp2OmAAGlAbgBAAByceBuscRn-wIAAAAABFla

bug

Most helpful comment

Good catch, we'll fix it in the next release which is planned for the week of Sept 28th (likely Oct 1). If this is a deal breaker for you, I suggest pinning to 19.10b0 in the mean time.

All 5 comments

Hello @mlissner.

The default line length limit is 88 so I don't see what is wrong with Black wrapping the docstring as it still fits. Do you happen to have a pyproject.toml configuration file?

Okay, now this bug makes sense. Thanks for clarifying!

Git bisect points to a4c11a7 as the first bad commit, from "Re-indent the contents of docstrings" (#1053).

Good catch, we'll fix it in the next release which is planned for the week of Sept 28th (likely Oct 1). If this is a deal breaker for you, I suggest pinning to 19.10b0 in the mean time.

Hi, is there an ETA for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

craigmac picture craigmac  路  3Comments

dgnsrekt picture dgnsrekt  路  3Comments

decibyte picture decibyte  路  3Comments

testvinder picture testvinder  路  3Comments

dusty-phillips picture dusty-phillips  路  3Comments