# HG changeset patch # User Paul Boddie # Date 1480896241 -3600 # Node ID 86368c6ae78b401afd4ce01e47a8f2e8dfa57881 # Parent 6acc19256bb90e5b8cc2fc63fc4dd29f63a9354f Make sure that imported names referring to non-static objects are initialised. diff -r 6acc19256bb9 -r 86368c6ae78b translator.py --- a/translator.py Mon Dec 05 00:20:28 2016 +0100 +++ b/translator.py Mon Dec 05 01:04:01 2016 +0100 @@ -23,6 +23,7 @@ from encoders import * from os.path import exists, join from os import makedirs +from referencing import Reference import compiler import results @@ -451,6 +452,11 @@ expr = self.process_structure_node(n.expr) self.statement(expr) + # Module import declarations. + + elif isinstance(n, compiler.ast.From): + self.process_from_node(n) + # Nodes using operator module functions. elif isinstance(n, compiler.ast.Operator): @@ -785,6 +791,33 @@ encode_path(parent), encode_symbol("pos", attrname) )) + def process_from_node(self, n): + + "Process the given node 'n', importing from another module." + + path = self.get_namespace_path() + + # Attempt to obtain the referenced objects. + + for name, alias in n.names: + if name == "*": + raise InspectError("Only explicitly specified names can be imported from modules.", path, n) + + # Obtain the path of the assigned name. + + objpath = self.get_object_path(alias or name) + + # Obtain the identity of the name. + + ref = self.importer.identify(objpath) + + # Where the name is not static, assign the value. + + if ref and not ref.static() and ref.get_name(): + self.writestmt("%s;" % + TrResolvedNameRef(alias or name, Reference("", None, objpath), + expr=TrResolvedNameRef(name, ref))) + def process_function_body_node(self, n): """