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

Consider uppercase docstring prefixes at D300. #176

Merged
merged 1 commit into from Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -4,6 +4,12 @@ Release Notes
**pydocstyle** version numbers follow the
`Semantic Versioning <http://semver.org/>`_ specification.

x.x.x - Current Development Version
-----------------------------------

* The error code D300 is now also being reported if a docstring has
uppercase literals (``R`` or ``U``) as prefix (#176).

1.0.0 - January 30th, 2016
--------------------------

Expand Down
20 changes: 11 additions & 9 deletions src/pydocstyle.py
Expand Up @@ -1554,15 +1554,17 @@ def check_triple_double_quotes(self, definition, docstring):
""" quotes in its body.

'''
if (docstring and '"""' in ast.literal_eval(docstring) and
docstring.startswith(("'''", "r'''", "u'''", "ur'''"))):
# Allow ''' quotes if docstring contains """, because otherwise """
# quotes could not be expressed inside docstring. Not in PEP 257.
return
if docstring and not docstring.startswith(
('"""', 'r"""', 'u"""', 'ur"""')):
quotes = "'''" if "'''" in docstring[:4] else "'"
return D300(quotes)
if docstring:
opening = docstring[:5].lower()
if '"""' in ast.literal_eval(docstring) and opening.startswith(
("'''", "r'''", "u'''", "ur'''")):
# Allow ''' quotes if docstring contains """, because
# otherwise """ quotes could not be expressed inside
# docstring. Not in PEP 257.
return
if not opening.startswith(('"""', 'r"""', 'u"""', 'ur"""')):
quotes = "'''" if "'''" in opening else "'"
return D300(quotes)

@check_for(Definition)
def check_backslashes(self, definition, docstring):
Expand Down
29 changes: 25 additions & 4 deletions src/tests/test_cases/test.py
Expand Up @@ -218,23 +218,44 @@ def multiline():


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


@expect('D300: Use """triple double quotes""" (found \'\'\'-quotes)')
def triple_single_quotes_raw_uppercase():
R'''Summary.'''


@expect('D300: Use """triple double quotes""" (found \'-quotes)')
def lalskklkjllkjl():
def single_quotes_raw():
r'Summary.'


@expect('D300: Use """triple double quotes""" (found \'-quotes)')
def single_quotes_raw_uppercase():
R'Summary.'


@expect('D300: Use """triple double quotes""" (found \'-quotes)')
@expect('D301: Use r""" if any backslashes in a docstring')
def lalsksdewnlkjl():
def single_quotes_raw_uppercase_backslash():
R'Sum\mary.'


@expect('D301: Use r""" if any backslashes in a docstring')
def double_quotes_backslash():
"""Sum\\mary."""


@expect('D301: Use r""" if any backslashes in a docstring')
def double_quotes_backslash_uppercase():
R"""Sum\\mary."""


if sys.version_info[0] <= 2:
@expect('D302: Use u""" for Unicode docstrings')
def lasewnlkjl():
def unicode_unmarked():
"""Юникод."""


Expand Down