Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Optional checks for multi-line docstring summary style. #174

Merged
merged 1 commit into from
Mar 25, 2016

Conversation

toroettg
Copy link
Contributor

Hello,

PEP 257 allows multi-line docstring summaries to start on the first or second line, as it is outlined in #44. I prefer one over the other and was looking for a way to perform consistency checks on my projects. Thus, I have added two optional error codes (D212, D213), which you might like to incorporate.

As those are more restrictive than PEP 257, both error codes should naturally be selected explicitly (and typically mutual exclusive) by the following. Otherwise, they are ignored.

pydocstyle --add-select=D212,D213 file_to_check.py

I have tried to touch as little as possible when implementing them. Please review if this is too cumbersome, or interferes with pydocstyle in a way I have not noticed.

Kind regards,
Tobias

@toroettg toroettg changed the title Added optional error codes D212 and D213. Optional checks for multi-line docstring summary style. Feb 20, 2016
@Nurdok
Copy link
Member

Nurdok commented Feb 21, 2016

Thanks for submitting this! The concept is good, and I'll try to review the code as soon as I can.


@expect('D212: Multi-line docstring summary does not start on the first line.')
def multi_line_starts_second_line():
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add some tests that use u"""...""" , r"""...""" ,etc. I suspect that if first not in ['"""', "'''"]: wont catch them all.

@jayvdb
Copy link
Member

jayvdb commented Feb 22, 2016

Fwiw, it was on my todo list; my main project wants to stablise our docstrings according to your D212 rule ;-) So I am thrilled to see this patch.

When you get a chance, please squash your two commits into a single commit. Thanks.

Just as an aside, I believe D213 equals H404. https://github.com/openstack-dev/hacking/blob/master/hacking/checks/docstrings.py#L77

@toroettg toroettg force-pushed the MultiLineStyleOption branch from e952a9f to 973d8d1 Compare February 22, 2016 15:26
@toroettg
Copy link
Contributor Author

@jayvdb

You are right, I've added additional checks, but they quickly grow tedious. Another
abstraction layer like @check_for(Content), to test only literals between docstring opening and closing, would come in handy to reduce redundancy.

Another enhancement for the test framework, which came to my mind, was to test against virtual files, whose content is generated dynamically at run time from definitions in test cases.

H404 seems to be equal to D212; I have somewhat harmonized this PR with their code, since I am reinventing the wheel already.

Kind regards,
Tobias

@jayvdb
Copy link
Member

jayvdb commented Feb 22, 2016

Another abstraction layer like @check_for(Content),
to test only literals between docstring opening and closing,
would come in handy to reduce redundancy.

That would be very nice. It would be a separate changeset.

@@ -14,4 +14,4 @@ Not all error codes are checked for by default. The default behavior is to
check only error codes that are part of the `PEP257
<http://www.python.org/dev/peps/pep-0257/>`_ official convention.

All of the above error codes are checked for by default except for D203.
All of the above error codes are checked for by default except for D203, D212 and D213.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you don't exceed 80 columns per line.

@Nurdok
Copy link
Member

Nurdok commented Feb 23, 2016

Make sure to also add your change to the changelog.

@toroettg toroettg force-pushed the MultiLineStyleOption branch from 973d8d1 to 53ff113 Compare March 12, 2016 17:03
@toroettg
Copy link
Contributor Author

I have adapted the PR to your requested changes. With the integration as a regular definition test, I had to remove the Unicode related test cases, since they are invalid in the current PyPy3 (v2.4.0). Those may be added to #178 if so desired.

Also, the expect decorator gets confused by required arguments. Please review the change at a_following_valid_function for any side effects.

@Nurdok Nurdok merged commit c3cd2dc into PyCQA:master Mar 25, 2016
@Nurdok
Copy link
Member

Nurdok commented Mar 25, 2016

@toroettg Merged! Thank you so much for your time and effort, and sorry for taking so long to merge this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants