Merge branch 'remove_E101_indent_char_resetting' into 'master'

Don't reset indent_char when we encounter E101

See merge request pycqa/flake8!357
This commit is contained in:
Ian Stapleton Cordasco 2019-09-25 23:42:44 +00:00
commit 6bae5f7ef6
4 changed files with 20 additions and 28 deletions

View file

@ -558,16 +558,13 @@ class FileChecker(object):
for result_single in result:
column_offset, text = result_single
error_code = self.report(
self.report(
error_code=None,
line_number=self.processor.line_number,
column=column_offset,
text=text,
line=(override_error_line or physical_line),
)
self.processor.check_physical_error(
error_code, physical_line
)
def process_tokens(self):
"""Process tokens and trigger checks.

View file

@ -261,12 +261,6 @@ class FileProcessor(object):
)
return arguments
def check_physical_error(self, error_code, line):
# type: (str, str) -> None
"""Update attributes based on error code and line."""
if error_code == "E101":
self.indent_char = line[0]
def generate_tokens(self): # type: () -> Generator[_Token, None, None]
"""Tokenize the file and yield the tokens.

View file

@ -51,6 +51,25 @@ index d64ac39..7d943de 100644
assert err == ''
def test_e101_indent_char_does_not_reset(tmpdir, capsys):
"""Ensure that E101 with an existing indent_char does not reset it."""
t_py_contents = """\
if True:
print('space indented')
s = '''\
\ttab indented
''' # noqa: E101
if True:
print('space indented')
"""
with tmpdir.as_cwd():
tmpdir.join('t.py').write(t_py_contents)
_call_main(['t.py'])
def test_statistics_option(tmpdir, capsys):
"""Ensure that `flake8 --statistics` works."""
with tmpdir.as_cwd():

View file

@ -146,24 +146,6 @@ def test_next_line(default_options):
assert file_processor.line_number == i
@pytest.mark.parametrize('error_code, line, expected_indent_char', [
('E101', '\t\ta = 1', '\t'),
('E101', ' a = 1', ' '),
('W101', 'frobulate()', None),
('F821', 'class FizBuz:', None),
])
def test_check_physical_error(
error_code, line, expected_indent_char, default_options,
):
"""Verify we update the indet char for the appropriate error code."""
file_processor = processor.FileProcessor('-', default_options, lines=[
'Line 1',
])
file_processor.check_physical_error(error_code, line)
assert file_processor.indent_char == expected_indent_char
@pytest.mark.parametrize('params, args, expected_kwargs', [
({'blank_before': True, 'blank_lines': True},
None,