mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +00:00
Merge branch 'bug/214' into 'master'
Avoid TypeErrors when handling a SyntaxError See merge request !121
This commit is contained in:
commit
c17043ff3f
2 changed files with 17 additions and 1 deletions
|
|
@ -253,7 +253,10 @@ class StyleGuide(object):
|
|||
int
|
||||
"""
|
||||
# NOTE(sigmavirus24): Apparently we're provided with 0-indexed column
|
||||
# numbers so we have to offset that here.
|
||||
# numbers so we have to offset that here. Also, if a SyntaxError is
|
||||
# caught, column_number may be None.
|
||||
if not column_number:
|
||||
column_number = 0
|
||||
error = Error(code, filename, line_number, column_number + 1, text,
|
||||
physical_line)
|
||||
error_is_selected = (self.should_report_error(error.code) is
|
||||
|
|
|
|||
|
|
@ -185,6 +185,19 @@ def test_handle_error_notifies_listeners(select_list, ignore_list, error_code):
|
|||
formatter.handle.assert_called_once_with(error)
|
||||
|
||||
|
||||
def test_handle_error_does_not_raise_type_errors():
|
||||
"""Verify that we handle our inputs better."""
|
||||
listener_trie = mock.create_autospec(notifier.Notifier, instance=True)
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
guide = style_guide.StyleGuide(create_options(select=['T111'], ignore=[]),
|
||||
listener_trie=listener_trie,
|
||||
formatter=formatter)
|
||||
|
||||
assert 1 == guide.handle_error(
|
||||
'T111', 'file.py', 1, None, 'error found', 'a = 1'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('select_list,ignore_list,error_code', [
|
||||
(['E111', 'E121'], [], 'E122'),
|
||||
(['E11', 'E12'], [], 'E132'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue