# HG changeset patch # User Paul Boddie # Date 1367443169 -7200 # Node ID b9e902f5020dd6ad8f061b4150d0d34918754dfb # Parent 87496106bdcc73af8da5e91a89c90c1a47aa350e Permit repeated evaluation of __builtins__.getattr and a final evaluation of the function with more complete knowledge of a program's constants. diff -r 87496106bdcc -r b9e902f5020d micropython/__init__.py --- a/micropython/__init__.py Wed May 01 23:17:32 2013 +0200 +++ b/micropython/__init__.py Wed May 01 23:19:29 2013 +0200 @@ -614,7 +614,9 @@ "Collect attribute references for the entire program." # Include names which may not be explicitly used in programs. - # NOTE: Potentially declare these when inspecting. + # NOTE: These would potentially be declared when inspecting, but the + # NOTE: only name involved currently (__call__) is implicit in + # NOTE: invocations and cannot be detected. for attrname in self.names_always_used: for objname in objtable.all_possible_objects([attrname]): @@ -629,6 +631,13 @@ for name in self.modules.keys(): self._collect_attributes(name, objtable) + # Even after all modules have been visited, there may be a need to + # re-evaluate getattr invocations in the context of constants now known + # to be used. + + if "__builtins__.getattr" in self.attribute_users_visited: + self._collect_attributes("__builtins__.getattr", objtable) + def add_attribute_to_visit(self, objname, attrname): """ @@ -663,7 +672,7 @@ types. """ - if from_name in self.attribute_users_visited: + if from_name != "__builtins__.getattr" and from_name in self.attribute_users_visited: return self.attribute_users_visited.add(from_name)