summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2010-10-07 18:46:23 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2010-10-07 18:46:23 +0200
commitc7744105ffc547156b9d014909fc2574e6d63f22 (patch)
treec46c5e2457a2a5a76d32464e0f4b06543796f000
parent5c66024331500205f55080e79ab1402d49bfb3fb (diff)
downloadastroid-git-c7744105ffc547156b9d014909fc2574e6d63f22.tar.gz
create a Set node
-rw-r--r--_nodes_ast.py8
-rw-r--r--node_classes.py12
-rw-r--r--nodes.py4
-rw-r--r--nodes_as_string.py4
4 files changed, 26 insertions, 2 deletions
diff --git a/_nodes_ast.py b/_nodes_ast.py
index b433b75a..a49a2fd1 100644
--- a/_nodes_ast.py
+++ b/_nodes_ast.py
@@ -570,6 +570,14 @@ class TreeRebuilder(RebuildVisitor):
newnode.set_line_info(newnode.last_child())
return newnode
+ def visit_set(self, node, parent):
+ """visit a Tuple node by returning a fresh instance of it"""
+ newnode = new.Set()
+ _lineno_parent(node, newnode, parent)
+ newnode.elts = [self.visit(child, newnode) for child in node.elts]
+ newnode.set_line_info(newnode.last_child())
+ return newnode
+
def visit_setcomp(self, node, parent):
"""visit a SetComp node by returning a fresh instance of it"""
newnode = new.SetComp()
diff --git a/node_classes.py b/node_classes.py
index 23f8ad5a..386fb55a 100644
--- a/node_classes.py
+++ b/node_classes.py
@@ -697,6 +697,18 @@ class Return(StmtMixIn, NodeNG):
value = None
+class Set(NodeNG, Instance, ParentAssignTypeMixin):
+ """class representing a Set node"""
+ _astng_fields = ('elts',)
+ elts = None
+
+ def pytype(self):
+ return '__builtin__.set' # XXX __builtin__ vs builtins
+
+ def itered(self):
+ return self.elts
+
+
class SetComp(NodeNG):
"""class representing a SetComp node"""
_astng_fields = ('elt', 'generators')
diff --git a/nodes.py b/nodes.py
index 5050e2f0..d46290d6 100644
--- a/nodes.py
+++ b/nodes.py
@@ -56,7 +56,7 @@ from logilab.astng.node_classes import Arguments, AssAttr, Assert, Assign, \
Comprehension, Const, Continue, Decorators, DelAttr, DelName, Delete, \
Dict, DictComp, Discard, Ellipsis, EmptyNode, ExceptHandler, Exec, \
ExtSlice, For, From, Getattr, Global, If, IfExp, Import, Index, Keyword, \
- List, ListComp, Name, Pass, Print, Raise, Return, SetComp, Slice, \
+ List, ListComp, Name, Pass, Print, Raise, Return, Set, SetComp, Slice, \
Subscript, TryExcept, TryFinally, Tuple, UnaryOp, While, With, Yield, \
const_factory
from logilab.astng.scoped_nodes import Module, GenExpr, Lambda, Function, Class
@@ -77,7 +77,7 @@ ALL_NODE_CLASSES = (
Module,
Pass, Print,
Raise, Return,
- SetComp, Slice, Subscript,
+ Set, SetComp, Slice, Subscript,
TryExcept, TryFinally, Tuple,
UnaryOp,
While, With,
diff --git a/nodes_as_string.py b/nodes_as_string.py
index 30e65d3d..76276d1f 100644
--- a/nodes_as_string.py
+++ b/nodes_as_string.py
@@ -330,6 +330,10 @@ class AsStringVisitor(ASTVisitor):
"""return a astng.Index node as string"""
return node.value.accept(self)
+ def visit_set(self, node):
+ """return an astng.Set node as string"""
+ return '{%s}' % ', '.join([child.accept(self) for child in node.elts])
+
def visit_setcomp(self, node):
"""return an astng.SetComp node as string"""
return '[%s %s]' % (node.elt.accept(self), ' '.join([n.accept(self)