summaryrefslogtreecommitdiff
path: root/pep8.py
diff options
context:
space:
mode:
authorSam Vilain <svilain@saymedia.com>2012-06-06 13:44:52 -0700
committerSam Vilain <svilain@saymedia.com>2012-06-06 14:10:57 -0700
commit7d06f2d5065d1efaf4e053a3a5db75e8cb15beb6 (patch)
tree72ec0b823c44761137ce8ca5b6133cd5e974024e /pep8.py
parentb8ddbf8566f23e755eeb240b2a946bdbedf091c3 (diff)
downloadpep8-7d06f2d5065d1efaf4e053a3a5db75e8cb15beb6.tar.gz
Relax E127/E128 for aligned homogenous tokens
When using visual indenting, there is a tendency to communicate through 'interpretive dance', which is an affectionate name I have for arbitrary extra whitespace inserted to visually communicate 'something' to the reader. The examples in the test suite all start with a token which matches the same token on the previous line. This new rule permits indents to a matching level as a token on the previous line, but only if the tokens are the same. Add some tests to show the quirks with the current rule, which allows the first visual indent line to align with any token whatsoever.
Diffstat (limited to 'pep8.py')
-rwxr-xr-xpep8.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/pep8.py b/pep8.py
index c4b8737..93fc77a 100755
--- a/pep8.py
+++ b/pep8.py
@@ -474,6 +474,7 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
indent_next = logical_line.endswith(':')
indent_string = None
+ indent_any = []
row = depth = 0
# remember how many brackets were opened on each line
parens = [0] * nrows
@@ -537,6 +538,9 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
elif hang == 4 or not is_visual:
yield (start, 'E123 closing bracket does not match '
'indentation of opening bracket\'s line')
+ elif token_type == tokenize.OP and (start[1], text) in indent_any:
+ # token lined up with matching one from a previous line, OK
+ pass
elif is_visual:
# Visual indent is verified
for d1 in range(d, depth + 1):
@@ -575,6 +579,8 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
indent[d] = set([i for i in indent[d] if i <= start[1]])
d -= 1
+ indent_any = []
+
# look for visual indenting
if ((parens[row] and token_type != tokenize.NL and
hasattr(indent[depth], 'add'))):
@@ -590,6 +596,10 @@ def continuation_line_indentation(logical_line, tokens, indent_level):
elif token_type == tokenize.STRING:
indent_string = start[1]
+ # let people line up tokens, if they truly must.
+ if token_type == tokenize.OP:
+ indent_any.append((start[1], text))
+
# keep track of bracket depth
if token_type == tokenize.OP:
if text in '([{':