Skip to content

Commit

Permalink
Merge branch 'remove_E101_indent_char_resetting' into 'master'
Browse files Browse the repository at this point in the history
Don't reset indent_char when we encounter E101

See merge request pycqa/flake8!357
  • Loading branch information
sigmavirus24 committed Sep 25, 2019
2 parents 121ea4f + fdcec28 commit 6bae5f7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
5 changes: 1 addition & 4 deletions src/flake8/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,13 @@ def run_physical_checks(self, physical_line, override_error_line=None):

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.
Expand Down
6 changes: 0 additions & 6 deletions src/flake8/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,6 @@ def keyword_arguments_for(self, parameters, arguments=None):
)
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.
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ def test_diff_option(tmpdir, capsys):
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():
Expand Down
18 changes: 0 additions & 18 deletions tests/unit/test_file_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6bae5f7

Please sign in to comment.