diff --git a/docs/release_notes.rst b/docs/release_notes.rst index cf0b6c9a..35ffd894 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -4,6 +4,12 @@ Release Notes **pydocstyle** version numbers follow the `Semantic Versioning `_ 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 -------------------------- diff --git a/src/pydocstyle.py b/src/pydocstyle.py index 3b79af83..27e92895 100644 --- a/src/pydocstyle.py +++ b/src/pydocstyle.py @@ -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): diff --git a/src/tests/test_cases/test.py b/src/tests/test_cases/test.py index 7d6bad06..8ee07c99 100644 --- a/src/tests/test_cases/test.py +++ b/src/tests/test_cases/test.py @@ -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(): """Юникод."""