-
Notifications
You must be signed in to change notification settings - Fork 189
Changes to match new class docstring standard of PEP257 #91
Conversation
The earlier behaviour was to have a blank line before and after a class docstring. New behaviour defined here: https://www.python.org/dev/peps/pep-0257/ "Insert a blank line after all docstrings (one-line or multi-line) that document a class -- generally speaking, the class's methods are separated from each other by a single blank line, and the docstring needs to be offset from the first method by a blank line."
Might be good to squash those two middle commits since they have near identical commit messages. Otherwise, 👍 |
Big fan of this PR :) |
Is it maybe possible to still allow 0 or 1 line above the class docstring? Otherwise this would require pywikibot to update all classes and remove the blank line between the class and docstring. |
@xZise has a point. If this is to be accepted in its current condition, a major version bump should be planned so users understand that a breaking change (as far as expected output is concerned) will be happening. |
On pywikibot you are already using --ignore on flake8 (w/flake8-docstrings): So you could simply add D203 to this list. I don't think the new wording of pep257 supports 0 or 1 blank lines. Might also be worth the effort to add blank line removal to @myint docformatter tool. |
Yeah, pyformat should also be made aware of this. |
Perhaps a default list of ignores? And then either setting |
I think we're trending towards a good solution. I think a default ignore set is good. I also think changing errors associated with codes is bad. Error codes should be immutable. So, I think this PR should be blocked until a new error code is covered to only check for an empty line after a class-level docstring. The error code that currently covers 1 before and 1 after should be turned off by adding it to the default ignore set. An error code should be added that covers 0 empty lines between a class declaration and the class docstring. That should also be off by default. Action items:
That's just my opinion though. |
Yeah it needs to be a new error code, because if you 'reuse' D203 there is no distinction between 'requiring one line above' or 'requiring no line above' and it would disable the test completely. Thinking about it there should be at least to modes: Require 0 or 1 line above and require 0 lines above. Optionally (but I don't need it, just for completeness) require 1 line above. But if it's possible to allow 0 or 1 line above we could wait for fixing our code but already new code could comply. Maybe error codes aren't the best idea but options, because currently the error codes make sense but with two or three options on how D203 should work. Although maybe D213 and D223 for the different modes of D2x3. And regarding that we ignore certain: Yes for now, look into the flake8-docstrings-mandatory env. We are trying to build towards that configuration (which is ignoring none). |
The current relevant error codes are:
The guideline for pep257.py is that the PEP257 spec should be the default behavior. However, it's possible to allow checks that aren't part of the spec, so long as they are turned on by default. Furthermore, it is best not to meddle with existing error codes as to not create confusion between versions. Therefore, this is what should logically happen:
Now, there are several ways to implement the default errors feature, while allowing the user to change what is being checked in a sane way:
I personally tend towards (1), because it's what pep8 does. However it can become less comfortable if there will be many defaultly ignored errors. I'm also wondering how we'll implement flags that check different conventions (like |
Oh sorry, I thought D203 was about both. Then most of my comment is not valid. Regarding Another idea would be to define how many lines D203 allows, so something like |
I opened a different issue for deciding how we're going to handle ignore lists, default error codes, different convention styles, etc. Please take a look and give your feedback at #96. |
As mentioned in #96 I don't really see how that changes the main problem with this PR, that there needs to be a sensible way to still allow the old way, allow both (for the conversion) or just the new way. |
This is implemented in #137. |
When upgrading from 0.2.1.post1 to 0.2.4, warning D203 gets re-enabled. This is the warning about "1 blank line required before class docstring", that was removed from PEP257 by Guido: PyCQA/pydocstyle#91 http://raspberry-python.blogspot.com/2015/01/significant-pep257-change.html It is replaced by D211 "No blank lines allowed before class docstring", but must be re-enabled because we're setting the ignore value in setup.cfg.
When upgrading from 0.2.1.post1 to 0.2.4, warning D203 gets re-enabled. This is the warning about "1 blank line required before class docstring", that was removed from PEP257 by Guido: PyCQA/pydocstyle#91 http://raspberry-python.blogspot.com/2015/01/significant-pep257-change.html It is replaced by D211 "No blank lines allowed before class docstring", but must be re-enabled because we're setting the ignore value in setup.cfg.
This is to match Guido's change here:
https://hg.python.org/peps/rev/9b715d8246db
and the reason is in a comment by Guido here (first comment at bottom):
http://raspberry-python.blogspot.com/2015/01/significant-pep257-change.html