# HG changeset patch # User Paul Boddie # Date 1473026115 -7200 # Node ID b9155817ebcc912428508250735b72a3dc94602b # Parent 97b24760968f415dee2731682d2e47ec97679aec Resolve hidden dependencies in initialisers. diff -r 97b24760968f -r b9155817ebcc resolving.py --- a/resolving.py Sun Sep 04 22:36:15 2016 +0200 +++ b/resolving.py Sun Sep 04 23:55:15 2016 +0200 @@ -46,9 +46,9 @@ def get_resolved_object(self, path): """ - Get the details of an object with the given 'path'. Where the object - has not been resolved, None is returned. This differs from the - get_object method used elsewhere in that it does not return an + Get the details of an object with the given 'path' within this module. + Where the object has not been resolved, None is returned. This differs + from the get_object method used elsewhere in that it does not return an unresolved object reference. """ @@ -61,6 +61,12 @@ else: return None + def get_resolved_global_or_builtin(self, name): + + "Return the resolved global or built-in object with the given 'name'." + + return self.get_global(name) or self.importer.get_object("__builtins__.%s" % name) + # Post-inspection resolution activities. def resolve(self): @@ -82,6 +88,9 @@ for name, ref in self.objects.items(): if ref.has_kind(""): ref = self.importer.get_object(name) + + # Alias the member and write back to the importer. + ref = ref.alias(name) self.importer.objects[name] = self.objects[name] = ref @@ -148,7 +157,7 @@ # Find global or built-in definitions. - ref = self.get_global_or_builtin(name) + ref = self.get_resolved_global_or_builtin(name) objpath = ref and (ref.final() or ref.get_name()) if objpath: self.name_references[key] = objpath @@ -349,6 +358,13 @@ else: continue + # Resolve any hidden dependencies involving external objects + # or unresolved names referring to globals or built-ins. + + if ref.has_kind(""): + ref = self.importer.get_object(ref.get_origin()) or \ + self.importer.get_object(self.name_references.get(ref.get_origin())) + # Convert class invocations to instances. if invocation: