1.1 --- a/micropython/inspect.py Tue Jun 05 01:30:05 2012 +0200
1.2 +++ b/micropython/inspect.py Tue Jun 05 01:54:54 2012 +0200
1.3 @@ -327,9 +327,13 @@
1.4 cls.set(name, self.expr, 0)
1.5 self.use_specific_attribute(cls.full_name(), name)
1.6
1.7 - def store_instance_attr(self, name):
1.8 + def store_instance_attr(self, name, tentative=False):
1.9
1.10 - "Record instance attribute 'name' in the current class."
1.11 + """
1.12 + Record instance attribute 'name' in the current class. If 'tentative' is
1.13 + set to a true value, the instance attribute will be discarded if a class
1.14 + attribute is observed.
1.15 + """
1.16
1.17 if self.in_method:
1.18
1.19 @@ -337,7 +341,7 @@
1.20 # Previous namespace is the class.
1.21
1.22 cls = self.namespaces[-2]
1.23 - cls.add_instance_attribute(name)
1.24 + cls.add_instance_attribute(name, tentative)
1.25
1.26 # NOTE: The instance attribute, although defined in a specific
1.27 # NOTE: class, obviously appears in all descendant classes.
1.28 @@ -514,6 +518,12 @@
1.29 # to be an instance.
1.30
1.31 else:
1.32 +
1.33 + # Record any instance attributes.
1.34 +
1.35 + if expr.name == "self":
1.36 + self.store_instance_attr(attrname, tentative=True)
1.37 +
1.38 attr = make_instance()
1.39
1.40 # Note usage of the attribute where a local is involved.