Esempio n. 1
0
 def visit_set(self, node, parent):
     """visit a Set 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
Esempio n. 2
0
 def visit_set(self, node, parent, assign_ctx=None):
     """visit a Set node by returning a fresh instance of it"""
     newnode = new.Set()
     _lineno_parent(node, newnode, parent)
     newnode.elts = [self.visit(child, newnode, assign_ctx)
                     for child in node.elts]
     return newnode
Esempio n. 3
0
def _getattr(self, name, *args, **kw):
    try:
        return Module_getattr(self, name, *args, **kw)
    except NotFoundError, e:
        if self.name.startswith('erp5.'):
            raise

        real_module = __import__(self.name, fromlist=[self.name], level=0)
        try:
            attr = getattr(real_module, name)
        except AttributeError:
            raise e

        # REQUEST object (or any object non acquisition-wrapped)
        if (isinstance(attr, str)
                and attr == '<Special Object Used to Force Acquisition>'):
            raise e

        try:
            origin_module_name = attr.__module__
        except AttributeError:
            from astroid import nodes
            if isinstance(attr, dict):
                ast = nodes.Dict(attr)
            elif isinstance(attr, list):
                ast = nodes.List(attr)
            elif isinstance(attr, tuple):
                ast = nodes.Tuple(attr)
            elif isinstance(attr, set):
                ast = nodes.Set(attr)
            else:
                try:
                    ast = nodes.Const(attr)
                except Exception:
                    raise e
        else:
            if self.name == origin_module_name:
                raise

            # ast_from_class() actually works for any attribute of a Module
            try:
                ast = MANAGER.ast_from_class(attr)
            except AstroidBuildingException:
                raise e

        self.locals[name] = [ast]
        return [ast]
Esempio n. 4
0
 def visit_set(self, node, parent):
     """visit a Set node by returning a fresh instance of it"""
     newnode = nodes.Set(node.lineno, node.col_offset, parent)
     newnode.postinit([self.visit(child, newnode) for child in node.elts])
     return newnode
Esempio n. 5
0
def set_node(draw, elt=const_node(), **kwargs):
    """Return a Set node with elements drawn from elt."""
    node = nodes.Set()
    node.postinit(draw(hs.sets(elt, **kwargs)))
    return node