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

Commit a29eeeb

Browse files
committed
Consider uppercase docstring prefixes at D300.
1 parent b413c56 commit a29eeeb

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

docs/release_notes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Release Notes
44
**pydocstyle** version numbers follow the
55
`Semantic Versioning <http://semver.org/>`_ specification.
66

7+
x.x.x - Current Development Version
8+
-----------------------------------
9+
10+
* The error code D300 is now also being reported if a docstring has
11+
uppercase literals (``R`` or ``U``) as prefix (#176).
12+
713
1.0.0 - January 30th, 2016
814
--------------------------
915

src/pydocstyle.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,15 +1554,17 @@ def check_triple_double_quotes(self, definition, docstring):
15541554
""" quotes in its body.
15551555
15561556
'''
1557-
if (docstring and '"""' in ast.literal_eval(docstring) and
1558-
docstring.startswith(("'''", "r'''", "u'''", "ur'''"))):
1559-
# Allow ''' quotes if docstring contains """, because otherwise """
1560-
# quotes could not be expressed inside docstring. Not in PEP 257.
1561-
return
1562-
if docstring and not docstring.startswith(
1563-
('"""', 'r"""', 'u"""', 'ur"""')):
1564-
quotes = "'''" if "'''" in docstring[:4] else "'"
1565-
return D300(quotes)
1557+
if docstring:
1558+
opening = docstring[:5].lower()
1559+
if '"""' in ast.literal_eval(docstring) and opening.startswith(
1560+
("'''", "r'''", "u'''", "ur'''")):
1561+
# Allow ''' quotes if docstring contains """, because
1562+
# otherwise """ quotes could not be expressed inside
1563+
# docstring. Not in PEP 257.
1564+
return
1565+
if not opening.startswith(('"""', 'r"""', 'u"""', 'ur"""')):
1566+
quotes = "'''" if "'''" in opening else "'"
1567+
return D300(quotes)
15661568

15671569
@check_for(Definition)
15681570
def check_backslashes(self, definition, docstring):

src/tests/test_cases/test.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,23 +218,44 @@ def multiline():
218218

219219

220220
@expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
221-
def lsfklkjllkjl():
221+
def triple_single_quotes_raw():
222222
r'''Summary.'''
223223

224224

225+
@expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
226+
def triple_single_quotes_raw_uppercase():
227+
R'''Summary.'''
228+
229+
225230
@expect('D300: Use """triple double quotes""" (found \'-quotes)')
226-
def lalskklkjllkjl():
231+
def single_quotes_raw():
227232
r'Summary.'
228233

229234

235+
@expect('D300: Use """triple double quotes""" (found \'-quotes)')
236+
def single_quotes_raw_uppercase():
237+
R'Summary.'
238+
239+
240+
@expect('D300: Use """triple double quotes""" (found \'-quotes)')
230241
@expect('D301: Use r""" if any backslashes in a docstring')
231-
def lalsksdewnlkjl():
242+
def single_quotes_raw_uppercase_backslash():
243+
R'Sum\mary.'
244+
245+
246+
@expect('D301: Use r""" if any backslashes in a docstring')
247+
def double_quotes_backslash():
232248
"""Sum\\mary."""
233249

234250

251+
@expect('D301: Use r""" if any backslashes in a docstring')
252+
def double_quotes_backslash_uppercase():
253+
R"""Sum\\mary."""
254+
255+
235256
if sys.version_info[0] <= 2:
236257
@expect('D302: Use u""" for Unicode docstrings')
237-
def lasewnlkjl():
258+
def unicode_unmarked():
238259
"""Юникод."""
239260

240261

0 commit comments

Comments
 (0)