def visit_from(self, node, parent): """visit a From node by returning a fresh instance of it""" names = [(alias.name, alias.asname) for alias in node.names] newnode = new.From(node.module or '', names, node.level) _set_infos(node, newnode, parent) # store From names to add them to locals after building self._from_nodes.append(newnode) return newnode
def visit_from(self, node, parent): """visit a From node by returning a fresh instance of it""" names = [(alias.name, alias.asname) for alias in node.names] newnode = new.From(node.module, names, node.level) self._set_infos(node, newnode, parent) self._store_from_node(newnode) return newnode
def visit_callfunc(self, node): """Hack fake imports into the tree after demandload calls.""" # XXX inaccurate hack if not getattr(node.func, 'name', '').endswith('demandload'): return # sanity check. if len(node.args) < 2: self.linter.add_message('WPC01', node=node) return if not isinstance(node.args[1], nodes.Const): self.linter.add_message('WPC02', node=node) return if node.args[1].value.find(" ") != -1: self.linter.add_message('WPC03', node=node) return # Ignore the first arg since it's gloals() for mod in (module.value for module in node.args[1:]): if not isinstance(mod, str): self.linter.add_message('WPC02', node=node) continue col = mod.find(':') if col == -1: # Argument to Import probably works like this: # "import foo, foon as spork" is # nodes.Import([('foo', None), ('foon', 'spork')]) # (not entirely sure though, have not found documentation. # The asname/importedname might be the other way around fex). new_node = nodes.Import() rebuilder._set_infos(node, new_node, node.parent) new_node.names = [(mod, mod)] #node.frame().add_local_node(new_node, mod) node.set_local(mod, new_node) else: for name in mod[col+1:].split(','): if sys.version_info < (2, 5): new_node = nodes.From(mod[:col], ((name, None),)) else: new_node = nodes.From(mod[:col], ((name, None),), 0) rebuilder._set_infos(node, new_node, node.parent) #node.frame().add_local_node(newstuff, name) node.set_local(name, new_node)
def attach_import_node(node, modname, membername): """create a From node and register it in the locals of the given node with the specified name """ from_node = nodes.From(modname, [(membername, None)]) _attach_local_node(node, from_node, membername)
def build_from_import(fromname, names): """create and initialize an astng From import statement""" return nodes.From(fromname, [(name, None) for name in names])
def visit_from(self, node, parent): """visit a From node by returning a fresh instance of it""" newnode = new.From(node.modname, node.names) self._set_infos(node, newnode, parent) self._store_from_node(newnode) return newnode