Skip to content

Commit 3dad6b5

Browse files
committed
Fix regression with multiple brackets; issue #214
1 parent b347754 commit 3dad6b5

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Changelog
88
* Fix ignoring too many checks when ``--select`` is used with codes
99
declared in a flake8 extension. (Issue #216)
1010

11+
* Fix regression with multiple brackets. (Issue #214)
12+
1113

1214
1.4.6 (2013-07-02)
1315
------------------

pep8.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
424424
parens = [0] * nrows
425425
# relative indents of physical lines
426426
rel_indent = [0] * nrows
427+
open_rows = [[0]]
427428
# visual indents
428429
indent_chances = {}
429430
last_indent = tokens[0][2]
@@ -448,17 +449,15 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
448449
# record the initial indent.
449450
rel_indent[row] = expand_indent(line) - indent_level
450451

451-
if depth:
452-
# a bracket expression in a continuation line.
453-
# find the line that it was opened on
454-
for open_row in range(row - 1, -1, -1):
455-
if parens[open_row]:
456-
break
457-
else:
458-
# an unbracketed continuation line (ie, backslash)
459-
open_row = 0
460-
hang = rel_indent[row] - rel_indent[open_row]
452+
# identify closing bracket
461453
close_bracket = (token_type == tokenize.OP and text in ']})')
454+
455+
# is the indent relative to an opening bracket line?
456+
valid_hang = 4 if (hang_closing or not close_bracket) else 0
457+
for open_row in reversed(open_rows[depth]):
458+
if rel_indent[row] == rel_indent[open_row] + valid_hang:
459+
break
460+
hang = rel_indent[row] - rel_indent[open_row]
462461
visual_indent = (not close_bracket and hang > 0 and
463462
indent_chances.get(start[1]))
464463

@@ -519,6 +518,9 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
519518
if text in '([{':
520519
depth += 1
521520
indent.append(0)
521+
if len(open_rows) == depth:
522+
open_rows.append([])
523+
open_rows[depth].append(row)
522524
parens[row] += 1
523525
if verbose >= 4:
524526
print("bracket depth %s seen, col %s, visual min = %s" %
@@ -532,13 +534,13 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
532534
for ind in list(indent_chances):
533535
if ind >= prev_indent:
534536
del indent_chances[ind]
537+
del open_rows[depth + 1:]
535538
depth -= 1
536539
if depth:
537540
indent_chances[indent[depth]] = True
538541
for idx in range(row, -1, -1):
539542
if parens[idx]:
540543
parens[idx] -= 1
541-
rel_indent[row] = rel_indent[idx]
542544
break
543545
assert len(indent) == depth + 1
544546
if start[1] not in indent_chances:

testsuite/E12not.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
fnct(1, 2, 3,
129129
4, 5, 6)
130130

131-
fnct(1, 2, 3
131+
fnct(1, 2, 3,
132132
4, 5, 6,
133133
7, 8, 9,
134134
10, 11)
@@ -578,4 +578,13 @@ def f():
578578
('abc'
579579
'def') == (
580580
'abc')
581+
582+
# issue 214
583+
bar(
584+
1).zap(
585+
2)
586+
587+
bar(
588+
1).zap(
589+
2)
581590
#

0 commit comments

Comments
 (0)