Docstrings reformatted to be too long
Closed this issue · 11 comments
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:
-
Create a file with this content:
def my_func(): """Remove punctuation and return cleaned string plus its length in tokens. """ pass
-
Reformat it
-
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:
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?
Sorry, should have mentioned we have it set to 79. I think this link has that config and you can still see it:
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?
Is there any update on this issue?
In my case it breaks flake8, which complains about the lines being too long.
@jensguballa no, there hasn't been any update on this issue. No one has stepped on and worked on a fix. Us maintainers have been working on other things (either we deem more important or want to work on) so this slipped under our radar. Sorry for not following through with our claim.
Some code examples we can add to tests with the black config/args you added would be amazing.
Do you by chance just not have flake8
configured to allow ~88 chars or not changing black's line length?
I am using black with its default configuration (88 chars), and I have set max-line-length = 88 in the flake section of setup.cfg. So I believe these should be consistent settings.
Here is a test script:
class _YamlBlockStyle(str):
"""Class used to indicate that a string shall be serialized using the block style.
"""
Line length is 86. After reformatting it is increased to 89:
class _YamlBlockStyle(str):
"""Class used to indicate that a string shall be serialized using the block style."""
This comment still has a functional example: #1632 (comment)