diff options
author | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-18 11:10:23 +0100 |
---|---|---|
committer | Sylvain Thénault <sylvain.thenault@logilab.fr> | 2009-03-18 11:10:23 +0100 |
commit | a4e3901403aa98c112c268e60d1ed2029d5041d3 (patch) | |
tree | 90db9d8a8f6fbf0fa002cca296cb65e32179911e | |
parent | 8a3b6f56c772b93954a7f9dc83ec07432dab7d79 (diff) | |
download | astroid-git-a4e3901403aa98c112c268e60d1ed2029d5041d3.tar.gz |
If expression support
--HG--
branch : _ast_compat
-rw-r--r-- | _nodes_ast.py | 2 | ||||
-rw-r--r-- | _nodes_compiler.py | 10 | ||||
-rw-r--r-- | nodes.py | 1 | ||||
-rw-r--r-- | nodes_as_string.py | 9 | ||||
-rw-r--r-- | utils.py | 3 |
5 files changed, 18 insertions, 7 deletions
diff --git a/_nodes_ast.py b/_nodes_ast.py index 180662e5..ef9a40ca 100644 --- a/_nodes_ast.py +++ b/_nodes_ast.py @@ -29,7 +29,7 @@ from _ast import (Assert, Assign, AugAssign, Ellipsis, Exec, For, Global, - If, Import, + If, IfExp, Import, Lambda, List, ListComp, Module, Name, diff --git a/_nodes_compiler.py b/_nodes_compiler.py index c8b8d20d..e31664d0 100644 --- a/_nodes_compiler.py +++ b/_nodes_compiler.py @@ -56,11 +56,11 @@ except ImportError: """dummy Decorators node, shouldn't be used with py < 2.4""" def __init__(self, nodes=None): self.nodes = nodes - -class With: - """dummy With node: if we are using py >= 2.5 we will use _ast; - but we need it for the other astng modules - """ + +# dummy python >= 2.5 nodes: if we are using py >= 2.5 we will use _ast; +# but we need it for the other astng modules +class With: pass +class IfExp: pass # introduced in python 2.5 From.level = 0 # will be overiden by instance attribute with py>=2.5 @@ -99,6 +99,7 @@ Getattr._astng_fields = ('expr',) # (former value), attr (now attrname), ctx GenExpr._astng_fields = ('elt', 'generators') Global._astng_fields = () If._astng_fields = ('test', 'body', 'orelse') +IfExp._astng_fields = ('test', 'body', 'orelse') Import._astng_fields = () Keyword._astng_fields = ('value',) Lambda._astng_fields = ('args', 'body',) diff --git a/nodes_as_string.py b/nodes_as_string.py index 174a33f9..88acd2d3 100644 --- a/nodes_as_string.py +++ b/nodes_as_string.py @@ -232,9 +232,16 @@ class AsStringVisitor(ASTVisitor): """return an astng.If node as string""" ifs = ['if %s:\n%s' % (node.test.accept(self), self._stmt_list(node.body))] if node.orelse: - ifs.append('else:\n%s' % self._stmt_list(node.orelse) ) + ifs.append('else:\n%s' % self._stmt_list(node.orelse)) return '\n'.join(ifs) + def visit_ifexp(self, node): + """return an astng.IfExp node as string""" + ifs = ['%s if %s' % (self._stmt_list(node.body), node.test.accept(self))] + if node.orelse: + ifs.append('else %s' % self._stmt_list(node.orelse)) + return ' '.join(ifs) + def visit_import(self, node): """return an astng.Import node as string""" return 'import %s' % _import_string(node.names) @@ -154,6 +154,9 @@ class ASTVisitor(object): def visit_if(self, node): """dummy method for visiting an If node""" + def visit_ifexp(self, node): + """dummy method for visiting an IfExp node""" + def visit_import(self, node): """dummy method for visiting an Import node""" |