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

Commit 727799d

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into numpy-conventions
# Conflicts: # src/pydocstyle.py
2 parents 427d3e4 + 3b2c23f commit 727799d

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
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: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,13 @@ def to_rst(cls):
719719
'"signature"')
720720
D403 = D4xx.create_error('D403', 'First word of the first line should be '
721721
'properly capitalized', '%r, not %r')
722-
D404 = D4xx.create_error('D404', 'Section name should be properly capitalized',
722+
D404 = D4xx.create_error('D404', 'First word of the docstring should not '
723+
'be `This`')
724+
D405 = D4xx.create_error('D405', 'Section name should be properly capitalized',
723725
'%r, not %r')
724-
D405 = D4xx.create_error('D405', 'Section name should not end with a colon',
726+
D406 = D4xx.create_error('D406', 'Section name should not end with a colon',
725727
'%r, not %r')
726-
D406 = D4xx.create_error('D406', 'Section underline should match the length '
728+
D407 = D4xx.create_error('D407', 'Section underline should match the length '
727729
'of the section\'s name', 'len(%r) == %r')
728730

729731

@@ -736,7 +738,7 @@ def __getattr__(self, item):
736738
'pep257': set(ErrorRegistry.get_error_codes()) - set(['D203', 'D212',
737739
'D213', 'D214',
738740
'D404', 'D405',
739-
'D406']),
741+
'D406', 'D407']),
740742
'numpy': set(ErrorRegistry.get_error_codes()) - set(['D203', 'D212',
741743
'D213', 'D402'])
742744
})
@@ -1475,7 +1477,6 @@ def check_no_blank_before(self, function, docstring): # def
14751477
There's no blank line either before or after the docstring.
14761478
14771479
"""
1478-
# NOTE: This does not take into account functions with groups of code.
14791480
if docstring:
14801481
before, _, after = function.source.partition(docstring)
14811482
blanks_before = list(map(is_blank, before.split('\n')[:-1]))
@@ -1730,6 +1731,19 @@ def check_capitalized(self, function, docstring):
17301731
if first_word != first_word.capitalize():
17311732
return D403(first_word.capitalize(), first_word)
17321733

1734+
@check_for(Definition)
1735+
def check_starts_with_this(self, function, docstring):
1736+
"""D404: First word of the docstring should not be `This`.
1737+
1738+
Docstrings should use short, simple language. They should not begin
1739+
with "This class is [..]" or "This module contains [..]".
1740+
1741+
"""
1742+
if docstring:
1743+
first_word = ast.literal_eval(docstring).split()[0]
1744+
if first_word.lower() == 'this':
1745+
return D404()
1746+
17331747
# Somewhat hard to determine if return value is mentioned.
17341748
# @check(Function)
17351749
def SKIP_check_return_type(self, function, docstring):
@@ -1786,12 +1800,12 @@ def check_numpy(self, definition, docstring):
17861800
yield D214(section)
17871801

17881802
if section not in line:
1789-
yield D404(section, line.strip())
1790-
elif line.strip().lower() == with_colon:
17911803
yield D405(section, line.strip())
1804+
elif line.strip().lower() == with_colon:
1805+
yield D406(section, line.strip())
17921806

17931807
if next_line.strip() != "-" * len(section):
1794-
yield D406(section, len(section))
1808+
yield D407(section, len(section))
17951809
else:
17961810
# The next line does not contain only dashes, so it's
17971811
# not likely to be a section header.

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)