def visit_importfrom(self, node, parent, assign_ctx=None): """visit a From node by returning a fresh instance of it""" names = [(alias.name, alias.asname) for alias in node.names] newnode = new.ImportFrom(node.module or '', names, node.level or None) _set_infos(node, newnode, parent) # store From names to add them to locals after building self._import_from_nodes.append(newnode) return newnode
def visit_importfrom(self, node, parent): """visit an ImportFrom node by returning a fresh instance of it""" names = [(alias.name, alias.asname) for alias in node.names] newnode = nodes.ImportFrom(node.module or '', names, node.level or None, getattr(node, 'lineno', None), getattr(node, 'col_offset', None), parent) # store From names to add them to locals after building self._import_from_nodes.append(newnode) return newnode
def transform_flask_from_long(node): '''Translates a flask.ext.wtf from-style import into a non-magical import. Translates: from flask.ext.wtf import Form from flask.ext.admin.model import InlineFormAdmin Into: from flask_wtf import Form from flask_admin.model import InlineFormAdmin ''' actual_module_name = make_non_magical_flask_import(node.modname) new_node = nodes.ImportFrom(actual_module_name, node.names, node.level) copy_node_info(node, new_node) mark_transformed(new_node) return new_node
def attach_import_node(node, modname, membername): """create a ImportFrom node and register it in the locals of the given node with the specified name """ from_node = nodes.ImportFrom(modname, [(membername, None)]) _attach_local_node(node, from_node, membername)
def build_from_import(fromname, names): """create and initialize an astroid ImportFrom import statement""" return nodes.ImportFrom(fromname, [(name, None) for name in names])