diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-18 16:09:53 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-18 16:09:53 +0100 |
commit | 6ac08a007866ae11d8f398245dfc05cee806b236 (patch) | |
tree | 4c60be8c4c4f0fb13bf14c4c3f6b71877f304eee | |
parent | 536f3efaaa298115a93fc34a7909c8c4c4260ca9 (diff) | |
download | astroid-git-6ac08a007866ae11d8f398245dfc05cee806b236.tar.gz |
lint fixes
--HG--
branch : _ast_compat
-rw-r--r-- | _nodes_ast.py | 73 | ||||
-rw-r--r-- | _nodes_compiler.py | 2 | ||||
-rw-r--r-- | nodes.py | 6 | ||||
-rw-r--r-- | protocols.py | 4 |
4 files changed, 43 insertions, 42 deletions
diff --git a/_nodes_ast.py b/_nodes_ast.py index 6adb92b5..52e6ce59 100644 --- a/_nodes_ast.py +++ b/_nodes_ast.py @@ -35,7 +35,7 @@ from _ast import (Assert, Assign, AugAssign, Name, Pass, Print, Raise, Return, - Slice, Sub, Subscript, + Slice, Subscript, TryExcept, TryFinally, Tuple, UnaryOp, While, With, @@ -79,38 +79,37 @@ from logilab.astng.utils import ASTVisitor Proxy_ = object -BIN_OP_CLASSES = {_Add: '+', - _BitAnd: '&', - _BitOr: '|', - _BitXor: '^', - _Div: '/', - _FloorDiv: '//', - _Mod: '%', - _Mult: '*', - _Pow: '**', - _Sub: '-', - _LShift: '<<', - _RShift: '>>'} - -BOOL_OP_CLASSES = {_And: 'and', - _Or: 'or'} - -UNARY_OP_CLASSES = {_UAdd: '+', - _USub: '-', - _Not: 'not', - _Invert: '~'} - -CMP_OP_CLASSES = {_Eq: '==', - _Gt: '>', - _GtE: '>=', - _In: 'in', - _Is: 'is', - _IsNot: 'is not', - _Lt: '<', - _LtE: '<=', - _NotEq: '!=', - _NotIn: 'not in', - } +_BIN_OP_CLASSES = {_Add: '+', + _BitAnd: '&', + _BitOr: '|', + _BitXor: '^', + _Div: '/', + _FloorDiv: '//', + _Mod: '%', + _Mult: '*', + _Pow: '**', + _Sub: '-', + _LShift: '<<', + _RShift: '>>'} + +_BOOL_OP_CLASSES = {_And: 'and', + _Or: 'or'} + +_UNARY_OP_CLASSES = {_UAdd: '+', + _USub: '-', + _Not: 'not', + _Invert: '~'} + +_CMP_OP_CLASSES = {_Eq: '==', + _Gt: '>', + _GtE: '>=', + _In: 'in', + _Is: 'is', + _IsNot: 'is not', + _Lt: '<', + _LtE: '<=', + _NotEq: '!=', + _NotIn: 'not in'} def _init_set_doc(node): @@ -203,10 +202,10 @@ class TreeRebuilder(ASTVisitor): del node.msg def visit_binop(self, node): - node.op = BIN_OP_CLASSES[node.op.__class__] + node.op = _BIN_OP_CLASSES[node.op.__class__] def visit_boolop(self, node): - node.op = BOOL_OP_CLASSES[node.op.__class__] + node.op = _BOOL_OP_CLASSES[node.op.__class__] def visit_callfunc(self, node): node.args.extend(node.keywords) @@ -216,7 +215,7 @@ class TreeRebuilder(ASTVisitor): _init_set_doc(node) def visit_compare(self, node): - node.ops = [(CMP_OP_CLASSES[op.__class__], expr) + node.ops = [(_CMP_OP_CLASSES[op.__class__], expr) for op, expr in zip(node.ops, node.comparators)] del node.comparators @@ -287,7 +286,7 @@ class TreeRebuilder(ASTVisitor): del node.slice, node.value def visit_unaryop(self, node): - node.op = UNARY_OP_CLASSES[node.op.__class__] + node.op = _UNARY_OP_CLASSES[node.op.__class__] def visit_with(self, node): """build compiler like node """ diff --git a/_nodes_compiler.py b/_nodes_compiler.py index 9abdfd90..675e797c 100644 --- a/_nodes_compiler.py +++ b/_nodes_compiler.py @@ -177,7 +177,7 @@ def generic__repr__(self): """simple representation method to override compiler.ast's methods""" return "<%s at 0x%x>" % (self.__class__.__name__, id(self)) -for name, value in ast.__dict__.items(): +for value in ast.__dict__.values(): try: if issubclass(value, ast.Node): value.__repr__ = generic__repr__ @@ -141,7 +141,11 @@ class NodeNG: def accept(self, visitor): klass = self.__class__.__name__ - func = getattr(visitor, "visit_" + REDIRECT.get(klass, klass).lower() ) + try: + func = getattr(visitor, "visit_" + REDIRECT.get(klass, klass).lower() ) + except AttributeError: + print self, self.lineno, self.fromlineno + raise return func(self) def get_children(self): diff --git a/protocols.py b/protocols.py index d7cb0e3e..070b0069 100644 --- a/protocols.py +++ b/protocols.py @@ -149,7 +149,7 @@ def _resolve_looppart(parts, asspath, context): itered = part.itered() except TypeError: continue # XXX log error - for stmt in part.itered(): + for stmt in itered: try: assigned = stmt.getitem(index, context) except (AttributeError, IndexError): @@ -157,7 +157,6 @@ def _resolve_looppart(parts, asspath, context): if not asspath: # we acheived to resolved the assigment path, # don't infer the last part - found = True yield assigned elif assigned is YES: break @@ -270,7 +269,6 @@ def _resolve_asspart(parts, asspath, context): if not asspath: # we acheived to resolved the assigment path, don't infer the # last part - found = True yield assigned elif assigned is YES: return |