diff options
author | Sam Vilain <svilain@saymedia.com> | 2012-06-06 13:44:52 -0700 |
---|---|---|
committer | Sam Vilain <svilain@saymedia.com> | 2012-06-06 14:10:57 -0700 |
commit | 7d06f2d5065d1efaf4e053a3a5db75e8cb15beb6 (patch) | |
tree | 72ec0b823c44761137ce8ca5b6133cd5e974024e | |
parent | b8ddbf8566f23e755eeb240b2a946bdbedf091c3 (diff) | |
download | pep8-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.
-rwxr-xr-x | pep8.py | 10 | ||||
-rw-r--r-- | testsuite/E12.py | 25 | ||||
-rw-r--r-- | testsuite/E12not.py | 16 |
3 files changed, 49 insertions, 2 deletions
@@ -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 '([{': diff --git a/testsuite/E12.py b/testsuite/E12.py index c5e767a..f5c7c97 100644 --- a/testsuite/E12.py +++ b/testsuite/E12.py @@ -160,4 +160,27 @@ troublesome_hash_ii = { "long key that tends to happen more when you're indented": "stringwithalongtoken you don't want to break", } -#: +#: E128 +foo(1, 2, 3, +4, 5, 6) +#: E128 +foo(1, 2, 3, + 4, 5, 6) +#: E128 +foo(1, 2, 3, + 4, 5, 6) +#: E128 +foo(1, 2, 3, + 4, 5, 6) +#: E127 +foo(1, 2, 3, + 4, 5, 6) +#: E127 +foo(1, 2, 3, + 4, 5, 6) +#: E127 +foo(1, 2, 3, + 4, 5, 6) +#: E127 +foo(1, 2, 3, + 4, 5, 6) diff --git a/testsuite/E12not.py b/testsuite/E12not.py index a29b14e..4a49375 100644 --- a/testsuite/E12not.py +++ b/testsuite/E12not.py @@ -363,7 +363,6 @@ def unicode2html(s): .replace('"', '"') .replace('\n', '<br>\n')) - # parser.add_option('--count', action='store_true', help="print total number of errors and warnings " @@ -422,3 +421,18 @@ troublefree_hash = { ("long key that tends to happen more " "when you're indented"): "stringwithalongtoken you don't want to break", } + +foo(1, 2, 3, + 4, 5, 6) + +# TODO +foo(1, 2, 3, + 4, 5, 6) +foo(1, 2, 3, + 4, 5, 6) +foo(1, 2, 3, + 4, 5, 6) +foo(1, 2, 3, + 4, 5, 6) +foo(1, 2, 3, + 4, 5, 6) |