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

Commit

Permalink
Merge pull request #264 from PyCQA/feature/unicode-bug-fix-258
Browse files Browse the repository at this point in the history
Fix bug where snowballstemmer chokes on Unicode word
  • Loading branch information
Nurdok committed Jun 10, 2017
2 parents 83ea19c + d4f2760 commit 812d8d1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/release_notes.rst
Expand Up @@ -17,6 +17,9 @@ Bug Fixes

* Fixed an issue where the ``--source`` flag would result in improperly
spaced output (#256, #257, #260).
* Fixed an issue where if a first word in a docstring had Unicode characters
and the docstring was not a unicode string, an exception would be raised
(#258, #264).


2.0.0 - April 18th, 2017
Expand Down
1 change: 0 additions & 1 deletion setup.py
@@ -1,5 +1,4 @@
from __future__ import with_statement
import os
from setuptools import setup

# Do not update the version manually - it is managed by `bumpversion`.
Expand Down
9 changes: 8 additions & 1 deletion src/pydocstyle/checker.py
Expand Up @@ -372,7 +372,14 @@ def check_imperative_mood(self, function, docstring): # def context
if check_word in IMPERATIVE_BLACKLIST:
return violations.D401b(first_word)

correct_form = IMPERATIVE_VERBS.get(stem(check_word))
try:
correct_form = IMPERATIVE_VERBS.get(stem(check_word))
except UnicodeDecodeError:
# This is raised when the docstring contains unicode
# characters in the first word, but is not a unicode
# string. In which case D302 will be reported. Ignoring.
return

if correct_form and correct_form != check_word:
return violations.D401(
correct_form.capitalize(),
Expand Down
5 changes: 5 additions & 0 deletions src/tests/test_cases/test.py
Expand Up @@ -271,6 +271,10 @@ def double_quotes_backslash_uppercase():
def unicode_unmarked():
"""Юникод."""

@expect('D302: Use u""" for Unicode docstrings')
def first_word_has_unicode_byte():
"""あy."""


@expect("D400: First line should end with a period (not 'y')")
def lwnlkjl():
Expand Down Expand Up @@ -376,5 +380,6 @@ def bad_decorated_function():
"""Bad (E501) but decorated"""
pass


expect(os.path.normcase(__file__ if __file__[-1] != 'c' else __file__[:-1]),
'D100: Missing docstring in public module')
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -11,7 +11,7 @@ envlist = py27, py33, py34, py35, pypy, docs
setenv =
LANG=C
LC_ALL=C
commands = py.test --pep8 --cache-clear -v src/tests
commands = py.test --pep8 --cache-clear -vv src/tests
deps =
-rrequirements/runtime.txt
-rrequirements/tests.txt
Expand Down

0 comments on commit 812d8d1

Please sign in to comment.