45
45
700 statements
46
46
900 syntax error
47
47
"""
48
- __version__ = '1.4.6a0 '
48
+ __version__ = '1.4.6 '
49
49
50
50
import os
51
51
import sys
63
63
from ConfigParser import RawConfigParser
64
64
65
65
DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__'
66
- DEFAULT_IGNORE = 'E226,E24'
66
+ DEFAULT_IGNORE = 'E123, E226,E24'
67
67
if sys .platform == 'win32' :
68
68
DEFAULT_CONFIG = os .path .expanduser (r'~\.pep8' )
69
69
else :
@@ -381,7 +381,8 @@ def indentation(logical_line, previous_logical, indent_char,
381
381
yield 0 , "E113 unexpected indentation"
382
382
383
383
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 ):
385
386
r"""
386
387
Continuation lines should align wrapped elements either vertically using
387
388
Python's implicit line joining inside parentheses, brackets and braces, or
@@ -458,7 +459,8 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
458
459
open_row = 0
459
460
hang = rel_indent [row ] - rel_indent [open_row ]
460
461
close_bracket = (token_type == tokenize .OP and text in ']})' )
461
- visual_indent = not close_bracket and indent_chances .get (start [1 ])
462
+ visual_indent = (not close_bracket and hang > 0 and
463
+ indent_chances .get (start [1 ]))
462
464
463
465
if close_bracket and indent [depth ]:
464
466
# closing bracket for visual indent
@@ -467,7 +469,8 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
467
469
"visual indentation" )
468
470
elif close_bracket and not hang :
469
471
# closing bracket matches indentation of opening bracket's line
470
- pass
472
+ if hang_closing :
473
+ yield start , "E133 closing bracket is missing indentation"
471
474
elif visual_indent is True :
472
475
# visual indent is verified
473
476
if not indent [depth ]:
@@ -481,7 +484,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
481
484
"under-indented for visual indent" )
482
485
elif hang == 4 or (indent_next and rel_indent [row ] == 8 ):
483
486
# hanging indent is verified
484
- if close_bracket :
487
+ if close_bracket and not hang_closing :
485
488
yield (start , "E123 closing bracket does not match "
486
489
"indentation of opening bracket's line" )
487
490
else :
@@ -535,6 +538,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
535
538
for idx in range (row , - 1 , - 1 ):
536
539
if parens [idx ]:
537
540
parens [idx ] -= 1
541
+ rel_indent [row ] = rel_indent [idx ]
538
542
break
539
543
assert len (indent ) == depth + 1
540
544
if start [1 ] not in indent_chances :
@@ -543,7 +547,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
543
547
544
548
last_token_multiline = (start [0 ] != end [0 ])
545
549
546
- if indent_next and rel_indent [ - 1 ] == 4 :
550
+ if indent_next and expand_indent ( line ) == indent_level + 4 :
547
551
yield (last_indent , "E125 continuation line does not distinguish "
548
552
"itself from next logical line" )
549
553
@@ -1183,6 +1187,7 @@ def __init__(self, filename=None, lines=None,
1183
1187
self ._logical_checks = options .logical_checks
1184
1188
self ._ast_checks = options .ast_checks
1185
1189
self .max_line_length = options .max_line_length
1190
+ self .hang_closing = options .hang_closing
1186
1191
self .verbose = options .verbose
1187
1192
self .filename = filename
1188
1193
if filename is None :
@@ -1693,8 +1698,9 @@ def get_parser(prog='pep8', version=__version__):
1693
1698
parser = OptionParser (prog = prog , version = version ,
1694
1699
usage = "%prog [options] input ..." )
1695
1700
parser .config_options = [
1696
- 'exclude' , 'filename' , 'select' , 'ignore' , 'max-line-length' , 'count' ,
1697
- 'format' , 'quiet' , 'show-pep8' , 'show-source' , 'statistics' , 'verbose' ]
1701
+ 'exclude' , 'filename' , 'select' , 'ignore' , 'max-line-length' ,
1702
+ 'hang-closing' , 'count' , 'format' , 'quiet' , 'show-pep8' ,
1703
+ 'show-source' , 'statistics' , 'verbose' ]
1698
1704
parser .add_option ('-v' , '--verbose' , default = 0 , action = 'count' ,
1699
1705
help = "print status messages, or debug with -vv" )
1700
1706
parser .add_option ('-q' , '--quiet' , default = 0 , action = 'count' ,
@@ -1729,6 +1735,9 @@ def get_parser(prog='pep8', version=__version__):
1729
1735
default = MAX_LINE_LENGTH ,
1730
1736
help = "set maximum allowed line length "
1731
1737
"(default: %default)" )
1738
+ parser .add_option ('--hang-closing' , action = 'store_true' ,
1739
+ help = "hang closing bracket instead of matching "
1740
+ "indentation of opening bracket's line" )
1732
1741
parser .add_option ('--format' , metavar = 'format' , default = 'default' ,
1733
1742
help = "set the error format [default|pylint|<custom>]" )
1734
1743
parser .add_option ('--diff' , action = 'store_true' ,
0 commit comments