Exemple #1
0
 def visit_import_from(self, node: ImportFrom) -> None:
     # We can't bind module names during the first pass, as the target module might be
     # unprocessed. However, we add dummy unbound imported names to the symbol table so
     # that we at least know that the name refers to a module.
     at_module = self.sem.is_module_scope()
     node.is_top_level = at_module
     if not at_module:
         return
     for name, as_name in node.names:
         imported_name = as_name or name
         if imported_name not in self.sem.globals:
             sym = create_indirect_imported_name(self.sem.cur_mod_node,
                                                 node.id, node.relative,
                                                 name)
             if sym:
                 self.add_symbol(imported_name, sym, context=node)
Exemple #2
0
 def visit_import_from(self, node: ImportFrom) -> None:
     # We can't bind module names during the first pass, as the target module might be
     # unprocessed. However, we add dummy unbound imported names to the symbol table so
     # that we at least know that the name refers to a module.
     at_module = self.sem.is_module_scope()
     node.is_top_level = at_module
     if not at_module:
         return
     for name, as_name in node.names:
         imported_name = as_name or name
         if imported_name not in self.sem.globals:
             sym = create_indirect_imported_name(self.sem.cur_mod_node,
                                                 node.id,
                                                 node.relative,
                                                 name)
             if sym:
                 self.add_symbol(imported_name, sym, context=node)
Exemple #3
0
 def visit_import_from(self, node: ImportFrom) -> None:
     if node.assignments:
         node.assignments = []
     else:
         # If the node is unreachable, don't reset entries: they point to something else!
         if node.is_unreachable: return
         if self.names:
             # Reset entries in the symbol table. This is necessary since
             # otherwise the semantic analyzer will think that the import
             # assigns to an existing name instead of defining a new one.
             for name, as_name in node.names:
                 imported_name = as_name or name
                 # This assert is safe since we check for self.names above.
                 assert self.file_node is not None
                 sym = create_indirect_imported_name(
                     self.file_node, node.id, node.relative, name)
                 if sym:
                     self.names[imported_name] = sym
Exemple #4
0
    def visit_import_from(self, node: ImportFrom) -> None:
        # Imports can include both overriding symbols and fresh ones,
        # and we need to clear both.
        node.assignments = []

        # If the node is unreachable, don't reset entries: they point to something else!
        if node.is_unreachable: return
        if self.names:
            # Reset entries in the symbol table. This is necessary since
            # otherwise the semantic analyzer will think that the import
            # assigns to an existing name instead of defining a new one.
            for name, as_name in node.names:
                imported_name = as_name or name
                # This assert is safe since we check for self.names above.
                assert self.file_node is not None
                sym = create_indirect_imported_name(self.file_node,
                                                    node.id,
                                                    node.relative,
                                                    name)
                if sym:
                    self.names[imported_name] = sym