summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-03-24 23:26:01 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-03-24 23:26:01 +0100
commitca37ce87c8446b13abf18d0a9079479914834ee1 (patch)
treef011557603f93ddfee20edc10b85ec17fe429bb5
parentbc112091ee1f171496cb1d5c181547544970f352 (diff)
downloadpep8-ca37ce87c8446b13abf18d0a9079479914834ee1.tar.gz
A false positivee E126 when indenting with tabs; closes #204
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py11
-rw-r--r--testsuite/E10.py13
-rw-r--r--testsuite/W19.py21
4 files changed, 41 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 913580d..7e3b45b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -19,6 +19,8 @@ Changelog
* Fix a false positive E126 with embedded colon. (Issue #144)
+* Fix a false positive E126 when indenting with tabs. (Issue #204)
+
* Fix behaviour when ``exclude`` is in the configuration file and
the current directory is not the project directory. (Issue #247)
diff --git a/pep8.py b/pep8.py
index b825068..3961037 100755
--- a/pep8.py
+++ b/pep8.py
@@ -382,7 +382,7 @@ def indentation(logical_line, previous_logical, indent_char,
def continued_indentation(logical_line, tokens, indent_level, hang_closing,
- noqa, verbose):
+ indent_char, noqa, verbose):
r"""
Continuation lines should align wrapped elements either vertically using
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,
indent_next = logical_line.endswith(':')
row = depth = 0
+ valid_hangs = (4,) if indent_char != '\t' else (4, 8)
# remember how many brackets were opened on each line
parens = [0] * nrows
# relative indents of physical lines
@@ -455,11 +456,11 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
close_bracket = (token_type == tokenize.OP and text in ']})')
# is the indent relative to an opening bracket line?
- valid_hang = 4 if (hang_closing or not close_bracket) else 0
for open_row in reversed(open_rows[depth]):
- if rel_indent[row] == rel_indent[open_row] + valid_hang:
+ hang = rel_indent[row] - rel_indent[open_row]
+ hanging_indent = hang in valid_hangs
+ if hanging_indent:
break
- hang = rel_indent[row] - rel_indent[open_row]
# is there any chance of visual indent?
visual_indent = (not close_bracket and hang > 0 and
indent_chances.get(start[1]))
@@ -478,7 +479,7 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
# visual indent is broken
yield (start, "E128 continuation line "
"under-indented for visual indent")
- elif hang == 4 or (indent_next and rel_indent[row] == 8):
+ elif hanging_indent or (indent_next and rel_indent[row] == 8):
# hanging indent is verified
if close_bracket and not hang_closing:
yield (start, "E123 closing bracket does not match "
diff --git a/testsuite/E10.py b/testsuite/E10.py
index 2b3825e..cd142e3 100644
--- a/testsuite/E10.py
+++ b/testsuite/E10.py
@@ -25,4 +25,17 @@ class TestP4Poller(unittest.TestCase):
def tearDown(self):
pass
+
+#
+#: E101 W191 W191
+if True:
+ foo(1,
+ 2)
+#: E101 E101 W191 W191
+def test_keys(self):
+ """areas.json - All regions are accounted for."""
+ expected = set([
+ u'Norrbotten',
+ u'V\xe4sterbotten',
+ ])
#:
diff --git a/testsuite/W19.py b/testsuite/W19.py
index 485ebac..3e303d9 100644
--- a/testsuite/W19.py
+++ b/testsuite/W19.py
@@ -4,7 +4,7 @@ if False:
#:
-#: E126 W191
+#: W191
y = x == 2 \
or x == 3
#: E101 W191
@@ -101,4 +101,23 @@ if os.path.exists(os.path.join(path, PEP8_BIN)):
if foo is None and bar is "frop" and \
blah == 'yeah':
blah = 'yeahnah'
+
+
+#
+#: W191 W191 W191
+if True:
+ foo(
+ 1,
+ 2)
+#: W191 W191 W191 W191 W191
+def test_keys(self):
+ """areas.json - All regions are accounted for."""
+ expected = set([
+ u'Norrbotten',
+ u'V\xe4sterbotten',
+ ])
+#: W191
+x = [
+ 'abc'
+]
#: