Skip to content

Commit a1d2db6

Browse files
committed
New option --hang-closing to replace E123 by E133; issue #103
1 parent ee9903d commit a1d2db6

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Changelog
1717

1818
* Correctly report other E12 errors when E123 is ignored. (Issue #103)
1919

20+
* New option `--hang-closing` to switch to the alternative style of
21+
closing bracket indentation for hanging indent. Add error E133 for
22+
closing bracket which is missing indentation. (Issue #103)
23+
2024
* Do not crash when running AST checks and the document contains null bytes.
2125
(Issue #184)
2226

pep8.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ def indentation(logical_line, previous_logical, indent_char,
381381
yield 0, "E113 unexpected indentation"
382382

383383

384-
def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
384+
def continued_indentation(logical_line, tokens, indent_level, hang_closing,
385+
noqa, verbose):
385386
r"""
386387
Continuation lines should align wrapped elements either vertically using
387388
Python's implicit line joining inside parentheses, brackets and braces, or
@@ -467,7 +468,8 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
467468
"visual indentation")
468469
elif close_bracket and not hang:
469470
# closing bracket matches indentation of opening bracket's line
470-
pass
471+
if hang_closing:
472+
yield start, "E133 closing bracket is missing indentation"
471473
elif visual_indent is True:
472474
# visual indent is verified
473475
if not indent[depth]:
@@ -481,7 +483,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
481483
"under-indented for visual indent")
482484
elif hang == 4 or (indent_next and rel_indent[row] == 8):
483485
# hanging indent is verified
484-
if close_bracket:
486+
if close_bracket and not hang_closing:
485487
yield (start, "E123 closing bracket does not match "
486488
"indentation of opening bracket's line")
487489
else:
@@ -1183,6 +1185,7 @@ def __init__(self, filename=None, lines=None,
11831185
self._logical_checks = options.logical_checks
11841186
self._ast_checks = options.ast_checks
11851187
self.max_line_length = options.max_line_length
1188+
self.hang_closing = options.hang_closing
11861189
self.verbose = options.verbose
11871190
self.filename = filename
11881191
if filename is None:
@@ -1686,8 +1689,9 @@ def get_parser(prog='pep8', version=__version__):
16861689
parser = OptionParser(prog=prog, version=version,
16871690
usage="%prog [options] input ...")
16881691
parser.config_options = [
1689-
'exclude', 'filename', 'select', 'ignore', 'max-line-length', 'count',
1690-
'format', 'quiet', 'show-pep8', 'show-source', 'statistics', 'verbose']
1692+
'exclude', 'filename', 'select', 'ignore', 'max-line-length',
1693+
'hang-closing', 'count', 'format', 'quiet', 'show-pep8',
1694+
'show-source', 'statistics', 'verbose']
16911695
parser.add_option('-v', '--verbose', default=0, action='count',
16921696
help="print status messages, or debug with -vv")
16931697
parser.add_option('-q', '--quiet', default=0, action='count',
@@ -1722,6 +1726,9 @@ def get_parser(prog='pep8', version=__version__):
17221726
default=MAX_LINE_LENGTH,
17231727
help="set maximum allowed line length "
17241728
"(default: %default)")
1729+
parser.add_option('--hang-closing', action='store_true',
1730+
help="hang closing bracket instead of matching "
1731+
"indentation of opening bracket's line")
17251732
parser.add_option('--format', metavar='format', default='default',
17261733
help="set the error format [default|pylint|<custom>]")
17271734
parser.add_option('--diff', action='store_true',

0 commit comments

Comments
 (0)