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

Commit 4975051

Browse files
committed
Merge pull request #183 from Nurdok/d404-this
Added D404: First word of the docstring should not be `This`
2 parents 2e1ec82 + e00dc31 commit 4975051

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

docs/error_codes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ check only error codes that are part of the `PEP257
1515
<http://www.python.org/dev/peps/pep-0257/>`_ official convention.
1616

1717
All of the above error codes are checked for by default except for D203,
18-
D212 and D213.
18+
D212, D213 and D404.

docs/release_notes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ Release Notes
77
Current Development Version
88
---------------------------
99

10+
New Features
11+
1012
* Added the optional error codes D212 and D213, for checking whether
1113
the summary of a multi-line docstring starts at the first line,
1214
respectively at the second line (#174).
1315

16+
* Added D404 - First word of the docstring should not be `This`. It is turned
17+
off by default (#183).
18+
19+
Bug Fixes
20+
1421
* The error code D300 is now also being reported if a docstring has
1522
uppercase literals (``R`` or ``U``) as prefix (#176).
1623

src/pydocstyle.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ def to_rst(cls):
699699
'"signature"')
700700
D403 = D4xx.create_error('D403', 'First word of the first line should be '
701701
'properly capitalized', '%r, not %r')
702+
D404 = D4xx.create_error('D404', 'First word of the docstring should not '
703+
'be `This`')
702704

703705

704706
class AttrDict(dict):
@@ -707,8 +709,10 @@ def __getattr__(self, item):
707709

708710

709711
conventions = AttrDict({
710-
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203', 'D212',
711-
'D213'])
712+
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203',
713+
'D212',
714+
'D213',
715+
'D404'])
712716
})
713717

714718

@@ -1431,7 +1435,6 @@ def check_no_blank_before(self, function, docstring): # def
14311435
There's no blank line either before or after the docstring.
14321436
14331437
"""
1434-
# NOTE: This does not take into account functions with groups of code.
14351438
if docstring:
14361439
before, _, after = function.source.partition(docstring)
14371440
blanks_before = list(map(is_blank, before.split('\n')[:-1]))
@@ -1680,6 +1683,19 @@ def check_capitalized(self, function, docstring):
16801683
if first_word != first_word.capitalize():
16811684
return D403(first_word.capitalize(), first_word)
16821685

1686+
@check_for(Definition)
1687+
def check_starts_with_this(self, function, docstring):
1688+
"""D404: First word of the docstring should not be `This`.
1689+
1690+
Docstrings should use short, simple language. They should not begin
1691+
with "This class is [..]" or "This module contains [..]".
1692+
1693+
"""
1694+
if docstring:
1695+
first_word = ast.literal_eval(docstring).split()[0]
1696+
if first_word.lower() == 'this':
1697+
return D404()
1698+
16831699
# Somewhat hard to determine if return value is mentioned.
16841700
# @check(Function)
16851701
def SKIP_check_return_type(self, function, docstring):

src/tests/test_cases/unicode_literals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
"""This is a module."""
2+
"""A module."""
33

44
from __future__ import unicode_literals
55
from .expected import Expectation

src/tests/test_decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .. import pydocstyle
1414

1515

16-
class TestParser:
16+
class TestParser(object):
1717
"""Check parsing of Python source code."""
1818

1919
def test_parse_class_single_decorator(self):

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ addopts = -rw
2828
[pep257]
2929
inherit = false
3030
convention = pep257
31+
add-select = D404

0 commit comments

Comments
 (0)