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

Commit

Permalink
Consider uppercase docstring prefixes at D300.
Browse files Browse the repository at this point in the history
  • Loading branch information
toroettg committed Mar 2, 2016
1 parent b413c56 commit a29eeeb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
6 changes: 6 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit a29eeeb

Please sign in to comment.