summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Vilain <svilain@saymedia.com>2012-05-27 12:39:02 -0700
committerSam Vilain <svilain@saymedia.com>2012-05-27 13:40:43 -0700
commitc98b761367f25b28532bb32c5b67138680a332fb (patch)
treee514e7ff84b08d11031cd99ed0e9dd3306bb919a
parent771bebd8abdaea77b502469e7b6a1a1160345d19 (diff)
downloadpep8-c98b761367f25b28532bb32c5b67138680a332fb.tar.gz
Fix continuation lines false positive on indented blocks
A block which started at an initial indent followed by a hanging indent would not work due to an array being badly primed. Fix it, and while we're fixing small things, remove some breakpoint/debugging code and an overly long line.
-rwxr-xr-xpep8.py17
-rw-r--r--testsuite/E12.py8
2 files changed, 15 insertions, 10 deletions
diff --git a/pep8.py b/pep8.py
index d5a699a..e8e51b1 100755
--- a/pep8.py
+++ b/pep8.py
@@ -445,7 +445,7 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
parens = [] # for looking back to see where a bracket was opened
max_physical_line = 0
visual_min = [None] # visual indent columns by indent depth
- rel_indent = [[0,indent_level]] # relative indents of physical lines
+ rel_indent = [[0, 0]] # relative indents of physical lines
last_indent = None
if options.verbose >= 3:
print ">>> " + tokens[0][4],
@@ -478,8 +478,6 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
for open_line in range(line - 1, -1, -1):
if len(parens[open_line]) > 0:
break
- if open_line is None:
- import pdb; pdb.set_trace()
# check to see if visual indenting is active
min_indent = visual_min[depth]
@@ -497,8 +495,6 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
# check that this line is either visually indented vs
# the opening parens, or a hanging indent.
- if len(parens[open_line]) == 0:
- import pdb; pdb.set_trace()
start_col, end_col = parens[open_line][-1]
if start[1] == start_col:
# visual. fine.
@@ -539,11 +535,12 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
visual_min[depth] = visual_min[depth - 1]
parens[line].append([start[1], end[1]])
if options.verbose >= 4:
- print "bracket depth {d} seen, col {c}, visual min = {m}".format(
- d=depth,
- c=start[1],
- m=visual_min[depth],
- )
+ print "bracket depth {d} seen, col {c}, visual min = {m}"\
+ .format(
+ d=depth,
+ c=start[1],
+ m=visual_min[depth],
+ )
elif len(parens[line]) > 0 and token_type != tokenize.NL:
# text after an open parens starts visual indenting
if visual_min[depth] is None:
diff --git a/testsuite/E12.py b/testsuite/E12.py
index 0d98b1c..d268a89 100644
--- a/testsuite/E12.py
+++ b/testsuite/E12.py
@@ -118,3 +118,11 @@ result = {
}
]
}
+#: Okay
+if bar:
+ return(
+ start, 'E122 lines starting with a '
+ 'closing bracket should be indented '
+ "to match that of the opening "
+ "bracket's line"
+ )