summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2015-02-05 18:51:21 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2015-02-05 18:51:21 +0200
commit7dce582db2cddc3fe62a5c745db9574fb6f22c7e (patch)
tree085f052a012b65b5a36b52b6e8e9663cbb7891c0
parent0963c1ff552782a9e4d18d653c330ea58937d47d (diff)
parentb4e4382b009d84cf0f7665aa872d6f01eeb5f6a1 (diff)
downloadpylint-7dce582db2cddc3fe62a5c745db9574fb6f22c7e.tar.gz
Merged in mihai_stan/pylint (pull request #217)
Catch enchant check exceptions. Closes issue #469.
-rw-r--r--checkers/spelling.py11
-rw-r--r--test/unittest_checker_spelling.py12
2 files changed, 22 insertions, 1 deletions
diff --git a/checkers/spelling.py b/checkers/spelling.py
index 6cc604a..f6edd5d 100644
--- a/checkers/spelling.py
+++ b/checkers/spelling.py
@@ -61,6 +61,9 @@ class SpellingChecker(BaseTokenChecker):
'%s\nDid you mean: \'%s\'?',
'wrong-spelling-in-docstring',
'Used when a word in docstring is not spelled correctly.'),
+ 'C0403': ('Invalid characters %r in a docstring',
+ 'invalid-characters-in-docstring',
+ 'Used when a word in docstring cannot be checked by enchant.'),
}
options = (('spelling-dict',
{'default' : '', 'type' : 'choice', 'metavar' : '<dict name>',
@@ -168,7 +171,13 @@ class SpellingChecker(BaseTokenChecker):
word = word[2:]
# If it is a known word, then continue.
- if self.spelling_dict.check(word):
+ try:
+ if self.spelling_dict.check(word):
+ continue
+ except enchant.errors.Error:
+ # this can only happen in docstrings, not comments
+ self.add_message('invalid-characters-in-docstring',
+ line=line_num, args=(word,))
continue
# Store word to private dict or raise a message.
diff --git a/test/unittest_checker_spelling.py b/test/unittest_checker_spelling.py
index 8b55042..c630eb2 100644
--- a/test/unittest_checker_spelling.py
+++ b/test/unittest_checker_spelling.py
@@ -76,6 +76,18 @@ class SpellingCheckerTest(CheckerTestCase):
"comet' or 'comment' or 'moment' or 'foment"))):
self.checker.visit_class(stmt)
+ @unittest.skipIf(spell_dict is None,
+ "missing python-enchant package or missing "
+ "spelling dictionaries")
+ @set_config(spelling_dict=spell_dict)
+ def test_invalid_docstring_characters(self):
+ stmt = test_utils.extract_node(
+ 'def fff():\n """test\\x00"""\n pass')
+ with self.assertAddsMessages(
+ Message('invalid-characters-in-docstring', line=2,
+ args=('test\x00',))):
+ self.checker.visit_function(stmt)
+
if __name__ == '__main__':
unittest.main()