PyCQA / docformatter

Formats docstrings to follow PEP 257
https://pypi.python.org/pypi/docformatter
MIT License
530 stars 62 forks source link

Bug: formatting outside of docstring when first word is "default" #165

Closed jamesbraza closed 1 year ago

jamesbraza commented 1 year ago

Pretty niche bug here, docformatter is formatting outside of the docstring:

def foo():
    default = 0  # Comment

    def bar():
        pass

Running docformatter==1.5.1 on this:

> docformatter a.py
--- before/a.py
+++ after/a.py
@@ -1,5 +1,4 @@
 def foo():
     default = 0  # Comment
-
     def bar():
         pass
weibullguy commented 1 year ago

This is the same as the issue in #156 where the blank line is removed when there is a comment following the last line in a code block. Closing as a duplicate to #156.

jamesbraza commented 1 year ago

Okay sounds good, didn't know they were the same issue.

@weibullguy one thing to note, is changing the variable name in the first line from default to something like ham, the issue goes away:

def foo():
    ham = 0  # Comment

    def bar():
        pass

docformatter seems to be matching the variable name, if that helps

weibullguy commented 1 year ago

@jamesbraza Thanks for the additional information. It's weird behavior for sure :confused: But all the information I can get is helpful.

weibullguy commented 1 year ago

@jamesbraza tag v1.6.1-rc1 should have the fix you need if you're interested in giving it a try before I officially release v1.6.1.

jamesbraza commented 1 year ago

I wasn't sure how to pip install the v1.6.1-rc1, I tried pip install --pre and got nothing. I went ahead git clone'd the repo, and confirmed that this issue is resolved with the current master commit f1b0fa688a.

Nice job, thank you! ✅