tmhedberg/SimpylFold

docstring folding not working with empty line

yxiong opened this issue · 2 comments

I noticed that when there is an empty line between the function definition and the doc string, or when the ): is put in a new line, the docstring folding does not work (see screenshot below). Is this the intended behavior? Is there a good way to enhance the plugin to support that case? Thanks!

Screen Shot 2021-09-23 at 12 02 25 PM

I wouldn't say that this is intentional, in that it would be nice for the plugin to work properly in this case, but it's unlikely that we'll add support for it.

For the sake of simplicity, SimpylFold does not implement a full-fledged parser for the Python syntax, but relies on regular expressions, which necessitates that we make certain assumptions about how your code is formatted. In particular, we assume that you follow the Python community's common formatting conventions, especially those dictated by PEP 8. Other formatting styles may be accepted by the Python interpreter, but we don't explicitly strive to fold correctly when dealing with styles that do not conform to PEP 8 and other common conventions.

While I don't believe PEP 8 specifically says anything about putting ): on its own line, there is a discussion on this topic where the majority consensus seems to be that this is a generally discouraged style.

On putting a blank line before a docstring, PEP 257 (on docstring conventions) states that, for single-line docstrings, "There's no blank line either before or after the docstring", and for multi-line docstrings, it discusses inserting a blank line after certain types of docstrings, but does not ever say to insert a blank line before the docstring, which I take to mean that this is also discouraged.

There's nothing wrong with using a different style, but we can't support everyone's unique preferred style while keeping SimpylFold simple. I'd accept a tiny patch to address your case if it (in my subjective opinion) does not make the plugin code more complicated, but otherwise, it's not something I'm going to spend time trying to support.

Thanks for the detailed response, @tmhedberg ! They are really helpful, especially the references to PEP 8 and discussion threads. I can use them in the future to convince others to follow the same convention so that this plugin works as much as possible :)