SublimeAutoDocstring
SublimeAutoDocstring copied to clipboard
Numpy style adds whitespace on blank lines / PEP8 W293
"""Description
Attributes
----------
The blank line between Description and Attributes has whitespace up to the indent, and this triggers a PEP8 warning on Anaconda. Is there a way to indent only the lines that have text?
I can add a check for blank lines easy enough, but I have the sense that's not the real problem in this case. In the Numpy style, section headers are supposed to line up with the first ". I can't replicate the docstring you pasted; is this for a module or a class? Do you have any settings that add extra spaces?
Ok, so basically this is what you see when you insert the default class
snippet for Python
This is what happens when you AutoDocstring it
Notice the PEP8 warning about the leading whitespace on that line.
My settings:
{
"style": "auto_numpy"
}
I should add that I love this Sublime extension and it's made my block comments super easy. The attribute detection and change detection is amazing. This is just a minor annoyance and I couldn't easily figure out where the indent for the blank line gets added in code or I would have fixed it and submitted a PR
Aha, now I understand the problem. Unfortunately, AutoDocstring isn't adding that indent, sublime text is when the snippet is pasted. If you ask me, the linter is being a little picky here, because the 'trim_whitespace_on_save' ST option will take care of this for you. I totally get that it's distracting to have your linter complaining this.
I think an easy solution is to add an extra search and replace on blank lines after a docstring is added. This has the added bonus of just being a few lines of code :)
I'm super glad this plugin is useful for you. I wrote it so that I could stop actively thinking about formatting, but I quickly realized it could be way more than that :)
I noticed your commit on the issue, and I force-reinstalled AutoDocstring from Package Control, but the version remained unchanged and the issue persisted. Is there something special that needs to happen so that Package Control serves the updated version? For now I'm probably just going to manually clone the repository into the Packages directory.
I did commit something and bump the version, although it doesn't really resolve this issue. My understanding of the Package Control plugin is that when I tag a commit, it should automatically update. I suppose I should double check that my understanding is correct.
The change that I made does fix this issue if "use_snippet" is set to False, since in that case, the plugin decides how the entire docstring is indented. However, when the plugin inserts a snippet, Sublime Text decides how the block is indented. I tried doing a search and replace after the snippet is inserted, but that doesn't work because the field regions are then out of date, so you can't easily tab through the fields to replace them with meaningful text. I suppose that defeats the purpose of using snippets in the first place. I also tried temporarily disabling auto_indent / smart_indent / etc., but that didn't help either. As always, any ideas are welcome.
Thanks for the note about use_snippet: I've set that to false to avoid the same problem, but I'd like to add another vote on this ticket. I just discovered AutoDocstring, and am loving it so far.
I also have PEP8 linting on so I was getting those little warning about the extra spaces. Setting "use_snippet": false
fixed the problem for me as well.