diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-06 10:46:39 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-06 10:46:39 +0100 |
commit | fb3a0dd20e6681223d811d5fd59d14ea0417c65b (patch) | |
tree | e35c89796df0775383d0d9f123aa44405db43482 | |
parent | 864d2f31b0d30a25d5986cb8682c5500454da6c8 (diff) | |
download | astroid-git-fb3a0dd20e6681223d811d5fd59d14ea0417c65b.tar.gz |
fix 2.4 support (more to be done)
--HG--
branch : _ast_compat
-rw-r--r-- | _nodes_compiler.py | 13 | ||||
-rw-r--r-- | nodes.py | 4 | ||||
-rw-r--r-- | nodes_as_string.py | 2 | ||||
-rw-r--r-- | rebuilder.py | 8 | ||||
-rw-r--r-- | scoped_nodes.py | 2 |
5 files changed, 20 insertions, 9 deletions
diff --git a/_nodes_compiler.py b/_nodes_compiler.py index be818e56..f8497fc4 100644 --- a/_nodes_compiler.py +++ b/_nodes_compiler.py @@ -176,12 +176,12 @@ def _nodify_args(values): for arg in values: if isinstance(arg, (tuple, list)): n = Tuple() - n.elts = _nodify(arg) + n.elts = _nodify_args(arg) else: - n = Name() - n.id = arg + n = AssName(None, None) + n.name = arg res.append(n) - return n + return res def args_compiler_to_ast(node): # insert Arguments node @@ -235,7 +235,10 @@ class TreeRebuilder(ASTVisitor): del node.code args_compiler_to_ast(node) - visit_lambda = visit_function + def visit_lambda(self, node): + node.body = node.code + del node.code + args_compiler_to_ast(node) def visit_class(self, node): # remove Stmt node @@ -587,7 +587,7 @@ class NoneType(Instance, NodeNG): def __repr__(self): return 'None' def get_children(self): - return () + return iter(()) __str__ = __repr__ class Bool(Instance, NodeNG): @@ -600,7 +600,7 @@ class Bool(Instance, NodeNG): def __repr__(self): return str(self.value) def get_children(self): - return () + return iter(()) __str__ = __repr__ CONST_NAME_TRANSFORMS = {'None': (NoneType, None), diff --git a/nodes_as_string.py b/nodes_as_string.py index c9538289..00267710 100644 --- a/nodes_as_string.py +++ b/nodes_as_string.py @@ -153,7 +153,7 @@ class AsStringVisitor(ASTVisitor): def visit_decorators(self, node): """return an astng.Decorators node as string""" - return '@%s\n' % '\n@'.join(item.accept(self) for item in node.items) + return '@%s\n' % '\n@'.join(item.accept(self) for item in node.nodes) def visit_dict(self, node): """return an astng.Dict node as string""" diff --git a/rebuilder.py b/rebuilder.py index d87eb09f..5378eb45 100644 --- a/rebuilder.py +++ b/rebuilder.py @@ -242,6 +242,14 @@ class RebuildVisitor(ASTVisitor): const.parent = node node.locals['__path__'] = [const] + def visit_const(self, node): + """visit an Name node to become astng""" + try: + cls, value = nodes.CONST_VALUE_TRANSFORMS[node.value] + node.__class__ = cls + except KeyError: + pass + def visit_name(self, node): """visit an Name node to become astng""" try: diff --git a/scoped_nodes.py b/scoped_nodes.py index f352366f..26304a68 100644 --- a/scoped_nodes.py +++ b/scoped_nodes.py @@ -88,7 +88,7 @@ class LocalsDictMixIn(object): if the name is already defined, ignore it """ assert self.locals is not None, (self, id(self)) - assert not stmt in self.locals.get(name, ()), (self, stmt) + #assert not stmt in self.locals.get(name, ()), (self, stmt) self.locals.setdefault(name, []).append(stmt) __setitem__ = set_local |