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

Commit b96fb9d

Browse files
committed
Added D404: First word of a docstring should not be This
1 parent dbf8d5f commit b96fb9d

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/pydocstyle.py

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

707709

708710
class AttrDict(dict):
@@ -711,8 +713,10 @@ def __getattr__(self, item):
711713

712714

713715
conventions = AttrDict({
714-
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203', 'D212',
715-
'D213'])
716+
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203',
717+
'D212',
718+
'D213',
719+
'D404'])
716720
})
717721

718722

@@ -1435,7 +1439,6 @@ def check_no_blank_before(self, function, docstring): # def
14351439
There's no blank line either before or after the docstring.
14361440
14371441
"""
1438-
# NOTE: This does not take into account functions with groups of code.
14391442
if docstring:
14401443
before, _, after = function.source.partition(docstring)
14411444
blanks_before = list(map(is_blank, before.split('\n')[:-1]))
@@ -1684,6 +1687,19 @@ def check_capitalized(self, function, docstring):
16841687
if first_word != first_word.capitalize():
16851688
return D403(first_word.capitalize(), first_word)
16861689

1690+
@check_for(Definition)
1691+
def check_starts_with_this(self, function, docstring):
1692+
"""D404: First word of the docstring should not be `This`.
1693+
1694+
Docstrings should use short, simple language. They should not begin
1695+
with "This class is [..]" or "This module contains [..]".
1696+
1697+
"""
1698+
if docstring:
1699+
first_word = ast.literal_eval(docstring).split()[0]
1700+
if first_word.lower() == 'this':
1701+
return D404()
1702+
16871703
# Somewhat hard to determine if return value is mentioned.
16881704
# @check(Function)
16891705
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):

src/tests/test_definitions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ def test_token_stream():
253253
assert stream.line == 1
254254

255255

256-
def test_pep257():
257-
"""Run domain-specific tests from test.py file."""
256+
def test_example_files():
257+
"""Run domain-specific tests from test case files."""
258258
test_cases = (
259259
'test',
260260
'unicode_literals',
@@ -275,4 +275,4 @@ def test_pep257():
275275
for error in results:
276276
assert isinstance(error, Error)
277277
results = set([(e.definition.name, e.message) for e in results])
278-
assert case_module.expectation.expected == results
278+
assert case_module.expectation.expected == results, test_case

0 commit comments

Comments
 (0)