summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt4
-rwxr-xr-xpep8.py17
2 files changed, 16 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 904f8a7..74496ea 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,6 +17,10 @@ Changelog
* Correctly report other E12 errors when E123 is ignored. (Issue #103)
+* New option `--hang-closing` to switch to the alternative style of
+ closing bracket indentation for hanging indent. Add error E133 for
+ closing bracket which is missing indentation. (Issue #103)
+
* Do not crash when running AST checks and the document contains null bytes.
(Issue #184)
diff --git a/pep8.py b/pep8.py
index 0cf7548..e05fa6a 100755
--- a/pep8.py
+++ b/pep8.py
@@ -381,7 +381,8 @@ def indentation(logical_line, previous_logical, indent_char,
yield 0, "E113 unexpected indentation"
-def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
+def continued_indentation(logical_line, tokens, indent_level, hang_closing,
+ noqa, verbose):
r"""
Continuation lines should align wrapped elements either vertically using
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):
"visual indentation")
elif close_bracket and not hang:
# closing bracket matches indentation of opening bracket's line
- pass
+ if hang_closing:
+ yield start, "E133 closing bracket is missing indentation"
elif visual_indent is True:
# visual indent is verified
if not indent[depth]:
@@ -481,7 +483,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
"under-indented for visual indent")
elif hang == 4 or (indent_next and rel_indent[row] == 8):
# hanging indent is verified
- if close_bracket:
+ if close_bracket and not hang_closing:
yield (start, "E123 closing bracket does not match "
"indentation of opening bracket's line")
else:
@@ -1183,6 +1185,7 @@ class Checker(object):
self._logical_checks = options.logical_checks
self._ast_checks = options.ast_checks
self.max_line_length = options.max_line_length
+ self.hang_closing = options.hang_closing
self.verbose = options.verbose
self.filename = filename
if filename is None:
@@ -1686,8 +1689,9 @@ def get_parser(prog='pep8', version=__version__):
parser = OptionParser(prog=prog, version=version,
usage="%prog [options] input ...")
parser.config_options = [
- 'exclude', 'filename', 'select', 'ignore', 'max-line-length', 'count',
- 'format', 'quiet', 'show-pep8', 'show-source', 'statistics', 'verbose']
+ 'exclude', 'filename', 'select', 'ignore', 'max-line-length',
+ 'hang-closing', 'count', 'format', 'quiet', 'show-pep8',
+ 'show-source', 'statistics', 'verbose']
parser.add_option('-v', '--verbose', default=0, action='count',
help="print status messages, or debug with -vv")
parser.add_option('-q', '--quiet', default=0, action='count',
@@ -1722,6 +1726,9 @@ def get_parser(prog='pep8', version=__version__):
default=MAX_LINE_LENGTH,
help="set maximum allowed line length "
"(default: %default)")
+ parser.add_option('--hang-closing', action='store_true',
+ help="hang closing bracket instead of matching "
+ "indentation of opening bracket's line")
parser.add_option('--format', metavar='format', default='default',
help="set the error format [default|pylint|<custom>]")
parser.add_option('--diff', action='store_true',