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

Commit 4a07057

Browse files
committed
Make D403 weaker to avoid false positives
1 parent f7c12a8 commit 4a07057

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

src/pep257.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from __future__ import with_statement
1515

1616
import os
17+
import string
1718
import sys
1819
import ast
1920
import copy
@@ -152,6 +153,10 @@ class Module(Definition):
152153
module = property(lambda self: self)
153154
all = property(lambda self: self._all)
154155

156+
def __init__(self, *args, **kwargs):
157+
super(Module, self).__init__(*args, **kwargs)
158+
self.name = self.name.lower()
159+
155160
def __str__(self):
156161
return 'at module level'
157162

@@ -1618,6 +1623,11 @@ def check_capitalized(self, function, docstring):
16181623
"""
16191624
if docstring:
16201625
first_word = ast.literal_eval(docstring).split()[0]
1626+
if first_word == first_word.upper():
1627+
return
1628+
for char in first_word:
1629+
if char not in string.ascii_letters and char != "'":
1630+
return
16211631
if first_word != first_word.capitalize():
16221632
return D403(first_word.capitalize(), first_word)
16231633

src/tests/test_cases/capitalization.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,43 @@ def empty_docstring():
1818
""""""
1919

2020

21-
@expect("D403: First word of the first line should be properly capitalized "
22-
"('Get', not 'GET')")
2321
def all_caps():
2422
"""GET the request."""
23+
24+
25+
def non_letter_characters():
26+
"""Create/Edit the doodli-do."""
27+
28+
29+
def more_non_letter_characters():
30+
"""(Un)register the user."""
31+
32+
33+
def even_more_non_letter():
34+
"""'laser' the planet."""
35+
36+
37+
def dash():
38+
"""git-push it."""
39+
40+
41+
def digit_in_word():
42+
"""sha1 the string."""
43+
44+
45+
@expect("D403: First word of the first line should be properly capitalized "
46+
"(\"Don't\", not \"Don'T\")")
47+
def partial_caps():
48+
"""Don'T do that."""
49+
50+
51+
@expect("D403: First word of the first line should be properly capitalized "
52+
"('Return', not 'ReTurn')")
53+
def more_partial_caps():
54+
"""ReTurn the field."""
55+
56+
57+
@expect("D403: First word of the first line should be properly capitalized "
58+
"('A', not 'a')")
59+
def just_one_more_example():
60+
"""a function."""

src/tests/test_cases/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,5 +303,5 @@ def inner_function():
303303
"""Do inner something."""
304304
return 0
305305

306-
expect(__file__ if __file__[-1] != 'c' else __file__[:-1],
306+
expect(__file__.lower() if __file__[-1] != 'c' else __file__[:-1].lower(),
307307
'D100: Missing docstring in public module')

0 commit comments

Comments
 (0)