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

Commit

Permalink
Fix IndexError on strange backslash docstring (#506)
Browse files Browse the repository at this point in the history
* Fix IndexError on strange backslash docstring

* Formatting fixes

Co-authored-by: Sambhav Kothari <sambhavs.email@gmail.com>
  • Loading branch information
asottile and samj1912 committed Aug 29, 2020
1 parent d5448f0 commit 4e467fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Release Notes
Current Development Version
---------------------------

Bug Fixes

* Fix ``IndexError`` crash on one-line backslashed docstrings (#506).


5.1.0 - August 22nd, 2020
---------------------------
Expand Down
7 changes: 4 additions & 3 deletions src/pydocstyle/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,11 @@ def check_indent(self, definition, docstring):
indents = [leading_space(l) for l in lines if not is_blank(l)]
if set(' \t') == set(''.join(indents) + indent):
yield violations.D206()
if (len(indents) > 1 and min(indents[:-1]) > indent or
indents[-1] > indent):
if (len(indents) > 1 and min(indents[:-1]) > indent) or (
len(indents) > 0 and indents[-1] > indent
):
yield violations.D208()
if min(indents) < indent:
if len(indents) > 0 and min(indents) < indent:
yield violations.D207()

@check_for(Definition)
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_cases/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ class inner():
pass

pass


def func_with_weird_backslash():
"""Test a function with a weird backslash.\
"""

0 comments on commit 4e467fe

Please sign in to comment.