1.1 --- a/micropython/inspect.py Thu Jun 28 22:58:02 2012 +0200
1.2 +++ b/micropython/inspect.py Fri Jun 29 01:11:02 2012 +0200
1.3 @@ -62,8 +62,8 @@
1.4 assignments to provide non-constant values.
1.5
1.6 Assignments to names are only really considered to cause the targets of such
1.7 -assignments to provide constant values if the targets reside in the module
1.8 -namespace or in class namespaces, subject to the above conditions.
1.9 +assignments to provide constant values if the targets reside in class
1.10 +namespaces, subject to the above conditions.
1.11
1.12 Assignments to names within functions are not generally considered to cause the
1.13 targets of such assignments to provide constant values since functions can be
1.14 @@ -370,7 +370,7 @@
1.15
1.16 return (self.namespaces[-1:] or [self])[0]
1.17
1.18 - def use_name(self, name, node=None, value=None):
1.19 + def use_name(self, name, node=None, value=None, ns=None):
1.20
1.21 """
1.22 Use the given 'name' within the current namespace/unit, either in
1.23 @@ -378,14 +378,17 @@
1.24 None) or unconditionally.
1.25 """
1.26
1.27 - if node is not None and isinstance(node, compiler.ast.Name):
1.28 + unit = self.get_namespace()
1.29 +
1.30 + # Handle attribute usage situations within the current unit.
1.31 +
1.32 + if node is not None and isinstance(node, compiler.ast.Name) and ns is unit:
1.33 self.use_attribute(node.name, name, value)
1.34
1.35 # For general name usage, declare usage of the given name from this
1.36 # particular unit.
1.37
1.38 else:
1.39 - unit = self.get_namespace()
1.40 self.importer.use_name(name, unit.full_name(), value)
1.41
1.42 def use_constant(self, const):
1.43 @@ -546,7 +549,7 @@
1.44
1.45 # Get the attribute and record its usage.
1.46
1.47 - if isinstance(value, (Class, Module)):
1.48 + if isinstance(value, Class):
1.49
1.50 # Check for class.__class__.
1.51
1.52 @@ -600,7 +603,7 @@
1.53 if expr.parent is self.get_namespace() and not self.get_namespace() is self:
1.54 self.define_attribute_accessor(expr.name, attrname, node, value)
1.55 else:
1.56 - self.use_name(attrname, node.expr, value)
1.57 + self.use_name(attrname, node.expr, value, ns=expr.parent)
1.58
1.59 def _visitConst(self, value):
1.60