# HG changeset patch # User Paul Boddie # Date 1341007351 -7200 # Node ID 32c00af8d15c2b3381384825466b9fbb1262447e # Parent bbc93a13ba1ea1822537b0194d4b36cf2fd1c18b Introduced attribute usage tracking on globals used in functions. diff -r bbc93a13ba1e -r 32c00af8d15c micropython/data.py --- a/micropython/data.py Fri Jun 29 01:44:08 2012 +0200 +++ b/micropython/data.py Sat Jun 30 00:02:31 2012 +0200 @@ -613,24 +613,26 @@ users = self.attribute_users[-1] + # If no users are defined for the name, provide the current namespace. + + if not users.has_key(name): + self._define_attribute_user_for_name(self.astnode, name) + # Add the usage to all current users. - if users.has_key(name): - for user in users[name]: - values = user._attrnames[name] - if values is None: - values = user._attrnames[name] = ObjectSet() - - # Add an entry for the attribute, optionally with an assigned - # value. - - values.add(attrname) - if value is not None: - values[attrname].add(value) - - return users[name] - else: - return [] + for user in users[name]: + values = user._attrnames[name] + if values is None: + values = user._attrnames[name] = ObjectSet() + + # Add an entry for the attribute, optionally with an assigned + # value. + + values.add(attrname) + if value is not None: + values[attrname].add(value) + + return users[name] def _define_attribute_user(self, node): diff -r bbc93a13ba1e -r 32c00af8d15c micropython/inspect.py --- a/micropython/inspect.py Fri Jun 29 01:44:08 2012 +0200 +++ b/micropython/inspect.py Sat Jun 30 00:02:31 2012 +0200 @@ -598,11 +598,14 @@ where such attributes are inferred from the usage. """ - # Access to attribute via a local in functions or classes but not + # Access to attributes via a local in functions or classes but not # modules (since module-level locals are globals that can be modified - # independently of the namespace). + # independently of the namespace), or access via a module global within + # a function. - if expr.parent is self.get_namespace() and not self.get_namespace() is self: + if expr.parent is self.get_namespace() and not self.get_namespace() is self or \ + expr.parent is self and self.in_function: + self.define_attribute_accessor(expr.name, attrname, node, value) else: self.use_name(attrname, node.expr, value, ns=expr.parent)