Exemplo n.º 1
0
 def visit_import(self, node, parent):
     """visit an Import node by returning a fresh instance of it"""
     newnode = new.Import()
     self._set_infos(node, newnode, parent)
     newnode.names = node.names
     self._save_import_locals(newnode)
     return newnode
Exemplo n.º 2
0
 def visit_import(self, node, parent):
     """visit a Import node by returning a fresh instance of it"""
     newnode = new.Import()
     self._set_infos(node, newnode, parent)
     newnode.names = [(alias.name, alias.asname) for alias in node.names]
     self._save_import_locals(newnode)
     return newnode
Exemplo n.º 3
0
 def visit_import(self, node, parent):
     """visit a Import node by returning a fresh instance of it"""
     newnode = new.Import()
     _set_infos(node, newnode, parent)
     newnode.names = [(alias.name, alias.asname) for alias in node.names]
     # save import names in parent's locals:
     for (name, asname) in newnode.names:
         name = asname or name
         newnode.parent.set_local(name.split('.')[0], newnode)
     return newnode
Exemplo n.º 4
0
 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)