Skip to content

Commit 9756409

Browse files
committed
Update pylama to version 1.3.0
1 parent 2ec13e2 commit 9756409

File tree

7 files changed

+163
-103
lines changed

7 files changed

+163
-103
lines changed

pylibs/pylama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:license: BSD, see LICENSE for more details.
66
"""
77

8-
version_info = 1, 1, 0
8+
version_info = 1, 3, 0
99

1010
__version__ = version = '.'.join(map(str, version_info))
1111
__project__ = __name__

pylibs/pylama/checkers/pep8.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
700 statements
4646
900 syntax error
4747
"""
48-
__version__ = '1.4.6a0'
48+
__version__ = '1.4.6'
4949

5050
import os
5151
import sys
@@ -63,7 +63,7 @@
6363
from ConfigParser import RawConfigParser
6464

6565
DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__'
66-
DEFAULT_IGNORE = 'E226,E24'
66+
DEFAULT_IGNORE = 'E123,E226,E24'
6767
if sys.platform == 'win32':
6868
DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8')
6969
else:
@@ -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
@@ -458,7 +459,8 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
458459
open_row = 0
459460
hang = rel_indent[row] - rel_indent[open_row]
460461
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]))
462464

463465
if close_bracket and indent[depth]:
464466
# closing bracket for visual indent
@@ -467,7 +469,8 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
467469
"visual indentation")
468470
elif close_bracket and not hang:
469471
# closing bracket matches indentation of opening bracket's line
470-
pass
472+
if hang_closing:
473+
yield start, "E133 closing bracket is missing indentation"
471474
elif visual_indent is True:
472475
# visual indent is verified
473476
if not indent[depth]:
@@ -481,7 +484,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
481484
"under-indented for visual indent")
482485
elif hang == 4 or (indent_next and rel_indent[row] == 8):
483486
# hanging indent is verified
484-
if close_bracket:
487+
if close_bracket and not hang_closing:
485488
yield (start, "E123 closing bracket does not match "
486489
"indentation of opening bracket's line")
487490
else:
@@ -535,6 +538,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
535538
for idx in range(row, -1, -1):
536539
if parens[idx]:
537540
parens[idx] -= 1
541+
rel_indent[row] = rel_indent[idx]
538542
break
539543
assert len(indent) == depth + 1
540544
if start[1] not in indent_chances:
@@ -543,7 +547,7 @@ def continued_indentation(logical_line, tokens, indent_level, noqa, verbose):
543547

544548
last_token_multiline = (start[0] != end[0])
545549

546-
if indent_next and rel_indent[-1] == 4:
550+
if indent_next and expand_indent(line) == indent_level + 4:
547551
yield (last_indent, "E125 continuation line does not distinguish "
548552
"itself from next logical line")
549553

@@ -1183,6 +1187,7 @@ def __init__(self, filename=None, lines=None,
11831187
self._logical_checks = options.logical_checks
11841188
self._ast_checks = options.ast_checks
11851189
self.max_line_length = options.max_line_length
1190+
self.hang_closing = options.hang_closing
11861191
self.verbose = options.verbose
11871192
self.filename = filename
11881193
if filename is None:
@@ -1693,8 +1698,9 @@ def get_parser(prog='pep8', version=__version__):
16931698
parser = OptionParser(prog=prog, version=version,
16941699
usage="%prog [options] input ...")
16951700
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']
16981704
parser.add_option('-v', '--verbose', default=0, action='count',
16991705
help="print status messages, or debug with -vv")
17001706
parser.add_option('-q', '--quiet', default=0, action='count',
@@ -1729,6 +1735,9 @@ def get_parser(prog='pep8', version=__version__):
17291735
default=MAX_LINE_LENGTH,
17301736
help="set maximum allowed line length "
17311737
"(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")
17321741
parser.add_option('--format', metavar='format', default='default',
17331742
help="set the error format [default|pylint|<custom>]")
17341743
parser.add_option('--diff', action='store_true',

pylibs/pylama/checkers/pyflakes/checker.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ def unusedAssignments(self):
192192
yield name, binding
193193

194194

195+
class GeneratorScope(Scope):
196+
pass
197+
198+
195199
class ModuleScope(Scope):
196200
pass
197201

@@ -319,11 +323,14 @@ def checkDeadScopes(self):
319323
self.report(messages.UnusedImport,
320324
importation.source, importation.name)
321325

322-
def pushFunctionScope(self):
323-
self.scopeStack.append(FunctionScope())
326+
def pushScope(self, scopeClass=FunctionScope):
327+
self.scopeStack.append(scopeClass())
328+
329+
def pushFunctionScope(self): # XXX Deprecated
330+
self.pushScope(FunctionScope)
324331

325-
def pushClassScope(self):
326-
self.scopeStack.append(ClassScope())
332+
def pushClassScope(self): # XXX Deprecated
333+
self.pushScope(ClassScope)
327334

328335
def report(self, messageClass, *args, **kwargs):
329336
self.messages.append(messageClass(self.filename, *args, **kwargs))
@@ -437,28 +444,22 @@ def handleNodeLoad(self, node):
437444
else:
438445
return
439446

440-
# try enclosing function scopes
447+
scopes = [scope for scope in self.scopeStack[:-1]
448+
if isinstance(scope, (FunctionScope, ModuleScope))]
449+
if isinstance(self.scope, GeneratorScope) and scopes[-1] != self.scopeStack[-2]:
450+
scopes.append(self.scopeStack[-2])
451+
452+
# try enclosing function scopes and global scope
441453
importStarred = self.scope.importStarred
442-
for scope in self.scopeStack[-2:0:-1]:
454+
for scope in reversed(scopes):
443455
importStarred = importStarred or scope.importStarred
444-
if not isinstance(scope, FunctionScope):
445-
continue
446456
try:
447457
scope[name].used = (self.scope, node)
448458
except KeyError:
449459
pass
450460
else:
451461
return
452462

453-
# try global scope
454-
importStarred = importStarred or self.scopeStack[0].importStarred
455-
try:
456-
self.scopeStack[0][name].used = (self.scope, node)
457-
except KeyError:
458-
pass
459-
else:
460-
return
461-
462463
# look in the built-ins
463464
if importStarred or name in self.builtIns:
464465
return
@@ -570,7 +571,7 @@ def handleDoctests(self, node):
570571
# leading whitespace: ...
571572
return
572573
node_offset = self.offset or (0, 0)
573-
self.pushFunctionScope()
574+
self.pushScope()
574575
for example in examples:
575576
try:
576577
tree = compile(example.source, "<doctest>", "exec", ast.PyCF_ONLY_AST)
@@ -632,7 +633,7 @@ def LISTCOMP(self, node):
632633
self.handleNode(node.elt, node)
633634

634635
def GENERATOREXP(self, node):
635-
self.pushFunctionScope()
636+
self.pushScope(GeneratorScope)
636637
# handle generators before element
637638
for gen in node.generators:
638639
self.handleNode(gen, node)
@@ -642,7 +643,7 @@ def GENERATOREXP(self, node):
642643
SETCOMP = GENERATOREXP
643644

644645
def DICTCOMP(self, node):
645-
self.pushFunctionScope()
646+
self.pushScope(GeneratorScope)
646647
for gen in node.generators:
647648
self.handleNode(gen, node)
648649
self.handleNode(node.key, node)
@@ -742,7 +743,7 @@ def addArgs(arglist):
742743

743744
def runFunction():
744745

745-
self.pushFunctionScope()
746+
self.pushScope()
746747
for name in args:
747748
self.addBinding(node, Argument(name, node), reportRedef=False)
748749
if isinstance(node.body, list):
@@ -777,7 +778,7 @@ def CLASSDEF(self, node):
777778
if not PY2:
778779
for keywordNode in node.keywords:
779780
self.handleNode(keywordNode, node)
780-
self.pushClassScope()
781+
self.pushScope(ClassScope)
781782
if self.withDoctest:
782783
self.deferFunction(lambda: self.handleDoctests(node))
783784
for stmt in node.body:
@@ -847,5 +848,3 @@ def EXCEPTHANDLER(self, node):
847848
if isinstance(node.name, str):
848849
self.handleNodeStore(node)
849850
self.handleChildren(node)
850-
851-
# pymode:lint=0

0 commit comments

Comments
 (0)