summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2014-03-23 18:37:35 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2014-03-23 18:37:35 +0100
commit5731082d257c6743225f4be3628082c50e7dc2ed (patch)
tree4e2796166d419b61f76d8ec4cee2c409467b54fd
parent68d72a5dd747e1cd6fee9f02b417a70f4d9ff7ca (diff)
downloadpep8-5731082d257c6743225f4be3628082c50e7dc2ed.tar.gz
Fix a false positive E124 for hanging indent: issue #254
-rw-r--r--CHANGES.txt2
-rwxr-xr-xpep8.py19
-rw-r--r--testsuite/E12.py13
-rw-r--r--testsuite/E12not.py29
4 files changed, 54 insertions, 9 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 972a25b..a840c10 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -15,6 +15,8 @@ Changelog
* Fix ``StyleGuide`` to parse the local configuration if the
keyword argument ``paths`` is specified. (Issue #246)
+* Fix a false positive E124 for hanging indent. (Issue #254)
+
1.4.6 (2013-07-02)
------------------
diff --git a/pep8.py b/pep8.py
index b9bc0ca..83ebc71 100755
--- a/pep8.py
+++ b/pep8.py
@@ -473,6 +473,16 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
# closing bracket matches indentation of opening bracket's line
if hang_closing:
yield start, "E133 closing bracket is missing indentation"
+ elif indent[depth] and start[1] < indent[depth]:
+ if visual_indent is not True:
+ # 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):
+ # hanging indent is verified
+ if close_bracket and not hang_closing:
+ yield (start, "E123 closing bracket does not match "
+ "indentation of opening bracket's line")
elif visual_indent is True:
# visual indent is verified
if not indent[depth]:
@@ -480,15 +490,6 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
elif visual_indent in (text, str):
# ignore token lined up with matching one from a previous line
pass
- elif indent[depth] and start[1] < indent[depth]:
- # 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):
- # hanging indent is verified
- if close_bracket and not hang_closing:
- yield (start, "E123 closing bracket does not match "
- "indentation of opening bracket's line")
else:
# indent is broken
if hang <= 0:
diff --git a/testsuite/E12.py b/testsuite/E12.py
index e49dd7a..7c91129 100644
--- a/testsuite/E12.py
+++ b/testsuite/E12.py
@@ -340,4 +340,17 @@ input1 = {'a': {'calc': 1 + 2}, 'b': 1
rv.update(d=('a' + 'b', 'c'),
e=42, f=(42
+ 42))
+#: E123
+if True:
+ def example_issue254():
+ return [node.copy(
+ (
+ replacement
+ # First, look at all the node's current children.
+ for child in node.children
+ # Replace them.
+ for replacement in replace(child)
+ ),
+ dict(name=token.undefined)
+ )]
#:
diff --git a/testsuite/E12not.py b/testsuite/E12not.py
index 655dd6b..a2f72ce 100644
--- a/testsuite/E12not.py
+++ b/testsuite/E12not.py
@@ -588,3 +588,32 @@ bar(
1).zap(
2)
#
+if True:
+
+ def example_issue254():
+ return [node.copy(
+ (
+ replacement
+ # First, look at all the node's current children.
+ for child in node.children
+ # Replace them.
+ for replacement in replace(child)
+ ),
+ dict(name=token.undefined)
+ )]
+
+
+def valid_example():
+ return [node.copy(properties=dict(
+ (key, val if val is not None else token.undefined)
+ for key, val in node.items()
+ ))]
+
+
+def other_example():
+ return [node.copy(properties=dict(
+ (key, val if val is not None else token.undefined)
+ for key, val in node.items()
+ ))]
+
+#