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

Commit a4fac47

Browse files
committed
Incorporated superfluous quote checking to D300.
1 parent 7e800fe commit a4fac47

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

docs/release_notes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ Current Development Version
1010
Major Updates
1111

1212
* Support for Python 2.6 has been dropped (#206, #217).
13-
* Support for PyPy3 2.6 has been temporarily dropped, until it will be
14-
equivalent to CPython 3.3+ (#223).
13+
* Support for PyPy3 has been temporarily dropped, until it will be
14+
equivalent to CPython 3.3+ and supported by ``pip`` (#223).
1515
* Support for the ``pep257`` console script has been dropped. Only the
1616
``pydocstyle`` console script should be used (#216, #218).
1717

1818
New Features
1919

2020
* Decorator-based skipping via ``--ignore-decorators`` has been added (#204).
2121
* Support for using pycodestyle style wildcards has been added (#72, #209).
22+
* Superfluous opening quotes are now reported as part of D300 (#166, #224).
2223

2324
Bug Fixes
2425

@@ -27,6 +28,7 @@ Bug Fixes
2728
underscore. This is a bugfix where "public module" (D100) was reported
2829
regardless of module name (#199, #222).
2930

31+
3032
1.1.1 - October 4th, 2016
3133
-------------------------
3234

docs/snippets/publicity.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ determined and what its effects are.
44

55

66
How publicity is determined
7-
===========================
7+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
88

99
Publicity for all constructs is determined as follows: a construct is
1010
considered *public* if -
@@ -27,7 +27,7 @@ name does not begin with a single underscore.
2727

2828

2929
How publicity affects error reports
30-
===================================
30+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3131

3232
The immediate effect of a construct being determined as private is that no
3333
D1xx errors will be reported for it (or its children, as the previous section

src/pydocstyle/checker.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,17 @@ def check_triple_double_quotes(self, definition, docstring):
275275
276276
'''
277277
if docstring:
278-
opening = docstring[:5].lower()
279-
if '"""' in ast.literal_eval(docstring) and opening.startswith(
280-
("'''", "r'''", "u'''", "ur'''")):
278+
if '"""' in ast.literal_eval(docstring):
281279
# Allow ''' quotes if docstring contains """, because
282280
# otherwise """ quotes could not be expressed inside
283281
# docstring. Not in PEP 257.
284-
return
285-
if not opening.startswith(('"""', 'r"""', 'u"""', 'ur"""')):
286-
quotes = "'''" if "'''" in opening else "'"
287-
return violations.D300(quotes)
282+
regex = re(r"[uU]?[rR]?'''[^'].*")
283+
else:
284+
regex = re(r'[uU]?[rR]?"""[^"].*')
285+
286+
illegal_matcher = re(r"""[uU]?[rR]?("+|'+).*""")
287+
if not regex.match(docstring):
288+
return violations.D300(illegal_matcher.match(docstring).group(1))
288289

289290
@check_for(Definition)
290291
def check_backslashes(self, definition, docstring):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""A valid module docstring."""
2+
3+
from .expected import Expectation
4+
5+
expectation = Expectation()
6+
expect = expectation.expect
7+
8+
9+
def correct_func():
10+
"""Three quotes in both sides."""
11+
12+
13+
@expect('D300: Use """triple double quotes""" (found """"-quotes)')
14+
def extra_opening():
15+
""""Extra quote on the left."""
16+
17+
18+
@expect('D300: Use """triple double quotes""" (found """""-quotes)')
19+
def two_extra_opening():
20+
"""""Two extra quotes on the left."""
21+

src/tests/test_definitions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ def test_token_stream():
276276
'multi_line_summary_start',
277277
'all_import',
278278
'all_import_as',
279+
'superfluous_quotes',
279280
])
280281
def test_pep257(test_case):
281282
"""Run domain-specific tests from test.py file."""

0 commit comments

Comments
 (0)