From fdcec2803a3d2e340b109996c62a7af898e87a99 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 24 Sep 2019 13:53:04 -0700 Subject: [PATCH] Don't reset indent_char when we encounter E101 --- src/flake8/checker.py | 5 +---- src/flake8/processor.py | 6 ------ tests/integration/test_main.py | 19 +++++++++++++++++++ tests/unit/test_file_processor.py | 18 ------------------ 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 2df7e42..a57df35 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -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. diff --git a/src/flake8/processor.py b/src/flake8/processor.py index dad4d7b..83e2afc 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -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. diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py index 72e9621..ea9355d 100644 --- a/tests/integration/test_main.py +++ b/tests/integration/test_main.py @@ -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(): diff --git a/tests/unit/test_file_processor.py b/tests/unit/test_file_processor.py index c3ae021..afae77d 100644 --- a/tests/unit/test_file_processor.py +++ b/tests/unit/test_file_processor.py @@ -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,