docformatter icon indicating copy to clipboard operation
docformatter copied to clipboard

Remove whitespaces in blank lines to be compliant with PEP 8

Open lordyavin opened this issue 5 years ago • 2 comments

If a docstring contains a blank line with whitspaces docformatter does not remove them. This does violate the a PEP 8 rule and pycodestyle.py raises "W293 blank line contains whitspaces".

FYI: I'm using YAPF first and then docformatter. Since YAPF leaves docstrings as they are, it's up to docformatter to fix it.

lordyavin avatar Jul 10 '19 12:07 lordyavin

I can't seem to reproduce the problem, can you give an example?

https://github.com/myint/docformatter/blob/7fa355102584e2d97e4a6251be9807d05c413d6f/test_docformatter.py#L253-L266

myint avatar Jul 13 '19 01:07 myint

@lordyavin can you confirm that your issue is given a docstring with the following whitespace

Summary line    \n
        \n
Elaborate description    \n

docformatter will strip the whitespaces after "line" and "description", but will leave untouched the whitespace on the line between. It is this un-removed whitespace on the blank line that pycodestyle complains about. docformatter should strip the whitespaces on the blank line as well.

This would be an enhancement to docformatter since the whitespace in the blank line is PEP-257 compliant, but not PEP-8 compliant.

weibullguy avatar Jul 24 '22 20:07 weibullguy

I'm sorry, I don't have access to the sources that I edited when I opened this issue and currently I don't use python very much. So I can't confirm your analysis.

lordyavin avatar Aug 17 '22 17:08 lordyavin

It may depend on the interpretation of PEP-257, which says Multi-line docstrings consist of a summary line just like a one-line docstring, followed by a blank line, together with The entire docstring is indented the same as the quotes at its first line (see example below)..

As the example has no whitespaces in the blank line, the second statement is not in effect for "blank lines", and PEP-257 seems to prefer the whitespaces removed.

In any case, I agree that this will be an enhancement; I usually run pydocformatter after applying Black, and Black removes the whitespaces for me.

misho104 avatar Aug 17 '22 23:08 misho104