docformatter icon indicating copy to clipboard operation
docformatter copied to clipboard

Incorrect pyproject.toml parsing of boolean values (e.g., for `--pre-summary-space`)

Open stes opened this issue 2 years ago • 1 comments

Both in the current github version (1def3c4) and the released PyPI version (v1.5.0) I get a unexpected behavior when configuring docformatter via the pyproject.toml file.

Test plan

cat > pyproject.toml << EOF                 
[tool.docformatter]
pre-summary-space = false
EOF

cat > test.py << EOF                        
class Test():      
    """Foo bar."""       

EOF

docformatter --version
docformatter --config pyproject.toml test.py

Additional context:

python -c "import docformatter.configuration; print(docformatter.configuration.TOMLI_INSTALLED)"
True

Expected output

No change. The file is already correctly formatted.

Actual output

A space is added in front of the summary line, which was disabled

docformatter 1.5.0
--- before/test.py
+++ after/test.py
@@ -1,3 +1,3 @@
 class Test():      
-    """Foo bar."""       
+    """ Foo bar."""

Investigation and work-around

There seems to be sth off with argument parsing. The error can be fixed by using the False defaults for pre-summary-space which was added in 1def3c4, i.e. this works:

cat > pyproject.toml << EOF                 
[tool.docformatter]
EOF

cat > test.py << EOF                        
class Test():      
    """Foo bar."""       

EOF

docformatter --config pyproject.toml test.py

and does not change the file. Note, this fix is not possible on the pypi version as the default for pre-summary-space is True there.

stes avatar Sep 22 '22 18:09 stes

This seems to happen with other options as well. Setting any of the following actually has the opposite effect.

pre-summary-newline = false
pre-summary-multi-line = false
blank = false

mdbenito avatar Oct 09 '22 11:10 mdbenito

This is not limited to boolean. I tried wrap-summaries = 12 and it didn't wrap anything.

galyfray avatar Dec 08 '22 21:12 galyfray