Skip to content

Commit ca37ce8

Browse files
committed
A false positivee E126 when indenting with tabs; closes #204
1 parent bc11209 commit ca37ce8

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Changelog
1919

2020
* Fix a false positive E126 with embedded colon. (Issue #144)
2121

22+
* Fix a false positive E126 when indenting with tabs. (Issue #204)
23+
2224
* Fix behaviour when ``exclude`` is in the configuration file and
2325
the current directory is not the project directory. (Issue #247)
2426

pep8.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def indentation(logical_line, previous_logical, indent_char,
382382

383383

384384
def continued_indentation(logical_line, tokens, indent_level, hang_closing,
385-
noqa, verbose):
385+
indent_char, noqa, verbose):
386386
r"""
387387
Continuation lines should align wrapped elements either vertically using
388388
Python's implicit line joining inside parentheses, brackets and braces, or
@@ -420,6 +420,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
420420
indent_next = logical_line.endswith(':')
421421

422422
row = depth = 0
423+
valid_hangs = (4,) if indent_char != '\t' else (4, 8)
423424
# remember how many brackets were opened on each line
424425
parens = [0] * nrows
425426
# relative indents of physical lines
@@ -455,11 +456,11 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
455456
close_bracket = (token_type == tokenize.OP and text in ']})')
456457

457458
# is the indent relative to an opening bracket line?
458-
valid_hang = 4 if (hang_closing or not close_bracket) else 0
459459
for open_row in reversed(open_rows[depth]):
460-
if rel_indent[row] == rel_indent[open_row] + valid_hang:
460+
hang = rel_indent[row] - rel_indent[open_row]
461+
hanging_indent = hang in valid_hangs
462+
if hanging_indent:
461463
break
462-
hang = rel_indent[row] - rel_indent[open_row]
463464
# is there any chance of visual indent?
464465
visual_indent = (not close_bracket and hang > 0 and
465466
indent_chances.get(start[1]))
@@ -478,7 +479,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
478479
# visual indent is broken
479480
yield (start, "E128 continuation line "
480481
"under-indented for visual indent")
481-
elif hang == 4 or (indent_next and rel_indent[row] == 8):
482+
elif hanging_indent or (indent_next and rel_indent[row] == 8):
482483
# hanging indent is verified
483484
if close_bracket and not hang_closing:
484485
yield (start, "E123 closing bracket does not match "

testsuite/E10.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,17 @@ def setUp(self):
2525

2626
def tearDown(self):
2727
pass
28+
29+
#
30+
#: E101 W191 W191
31+
if True:
32+
foo(1,
33+
2)
34+
#: E101 E101 W191 W191
35+
def test_keys(self):
36+
"""areas.json - All regions are accounted for."""
37+
expected = set([
38+
u'Norrbotten',
39+
u'V\xe4sterbotten',
40+
])
2841
#:

testsuite/W19.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#:
55

66

7-
#: E126 W191
7+
#: W191
88
y = x == 2 \
99
or x == 3
1010
#: E101 W191
@@ -101,4 +101,23 @@ def long_function_name(
101101
if foo is None and bar is "frop" and \
102102
blah == 'yeah':
103103
blah = 'yeahnah'
104+
105+
106+
#
107+
#: W191 W191 W191
108+
if True:
109+
foo(
110+
1,
111+
2)
112+
#: W191 W191 W191 W191 W191
113+
def test_keys(self):
114+
"""areas.json - All regions are accounted for."""
115+
expected = set([
116+
u'Norrbotten',
117+
u'V\xe4sterbotten',
118+
])
119+
#: W191
120+
x = [
121+
'abc'
122+
]
104123
#:

0 commit comments

Comments
 (0)