Skip to content

Commit 5731082

Browse files
committed
Fix a false positive E124 for hanging indent: issue #254
1 parent 68d72a5 commit 5731082

4 files changed

Lines changed: 54 additions & 9 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Changelog
1515
* Fix ``StyleGuide`` to parse the local configuration if the
1616
keyword argument ``paths`` is specified. (Issue #246)
1717

18+
* Fix a false positive E124 for hanging indent. (Issue #254)
19+
1820

1921
1.4.6 (2013-07-02)
2022
------------------

pep8.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,22 +473,23 @@ def continued_indentation(logical_line, tokens, indent_level, hang_closing,
473473
# closing bracket matches indentation of opening bracket's line
474474
if hang_closing:
475475
yield start, "E133 closing bracket is missing indentation"
476+
elif indent[depth] and start[1] < indent[depth]:
477+
if visual_indent is not True:
478+
# visual indent is broken
479+
yield (start, "E128 continuation line "
480+
"under-indented for visual indent")
481+
elif hang == 4 or (indent_next and rel_indent[row] == 8):
482+
# hanging indent is verified
483+
if close_bracket and not hang_closing:
484+
yield (start, "E123 closing bracket does not match "
485+
"indentation of opening bracket's line")
476486
elif visual_indent is True:
477487
# visual indent is verified
478488
if not indent[depth]:
479489
indent[depth] = start[1]
480490
elif visual_indent in (text, str):
481491
# ignore token lined up with matching one from a previous line
482492
pass
483-
elif indent[depth] and start[1] < indent[depth]:
484-
# visual indent is broken
485-
yield (start, "E128 continuation line "
486-
"under-indented for visual indent")
487-
elif hang == 4 or (indent_next and rel_indent[row] == 8):
488-
# hanging indent is verified
489-
if close_bracket and not hang_closing:
490-
yield (start, "E123 closing bracket does not match "
491-
"indentation of opening bracket's line")
492493
else:
493494
# indent is broken
494495
if hang <= 0:

testsuite/E12.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,17 @@ def qualify_by_address(self, cr, uid, ids, context=None,
340340
rv.update(d=('a' + 'b', 'c'),
341341
e=42, f=(42
342342
+ 42))
343+
#: E123
344+
if True:
345+
def example_issue254():
346+
return [node.copy(
347+
(
348+
replacement
349+
# First, look at all the node's current children.
350+
for child in node.children
351+
# Replace them.
352+
for replacement in replace(child)
353+
),
354+
dict(name=token.undefined)
355+
)]
343356
#:

testsuite/E12not.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,32 @@ def f():
588588
1).zap(
589589
2)
590590
#
591+
if True:
592+
593+
def example_issue254():
594+
return [node.copy(
595+
(
596+
replacement
597+
# First, look at all the node's current children.
598+
for child in node.children
599+
# Replace them.
600+
for replacement in replace(child)
601+
),
602+
dict(name=token.undefined)
603+
)]
604+
605+
606+
def valid_example():
607+
return [node.copy(properties=dict(
608+
(key, val if val is not None else token.undefined)
609+
for key, val in node.items()
610+
))]
611+
612+
613+
def other_example():
614+
return [node.copy(properties=dict(
615+
(key, val if val is not None else token.undefined)
616+
for key, val in node.items()
617+
))]
618+
619+
#

0 commit comments

Comments
 (0)