1.1 --- a/micropython/__init__.py Mon Jun 04 01:03:02 2012 +0200
1.2 +++ b/micropython/__init__.py Mon Jun 04 01:20:39 2012 +0200
1.3 @@ -728,10 +728,19 @@
1.4 # properly collect usage from it.
1.5
1.6 parent = attr.parent
1.7 +
1.8 + # NOTE: At this point, parent should never be None.
1.9 +
1.10 if parent is None:
1.11 continue
1.12 +
1.13 + # Instances provide the same identity as the object name.
1.14 +
1.15 elif isinstance(parent, Instance):
1.16 parentname = objname
1.17 +
1.18 + # In general, the fully qualified name is obtained.
1.19 +
1.20 else:
1.21 parentname = parent.full_name()
1.22
1.23 @@ -739,31 +748,37 @@
1.24
1.25 if attrvalues:
1.26
1.27 - # Instance-related accesses may involve any type
1.28 - # supporting the attribute.
1.29 - # NOTE: Here, an instance actually represents any kind
1.30 - # NOTE: of object.
1.31 + # NOTE: Here, an instance can actually represent any
1.32 + # NOTE: kind of object.
1.33
1.34 if isinstance(parent, Instance):
1.35 - for attrvalue in attrvalues:
1.36 - for name in objtable.any_possible_objects([attrname]):
1.37 +
1.38 + # Get the parent object using the special
1.39 + # table entry.
1.40
1.41 - # Get the parent object using the special
1.42 - # table entry.
1.43 + parent = objtable.access(objname, "#" + objname)
1.44
1.45 - parent = objtable.access(name, "#" + name)
1.46 + # Permit assignment to known instance attributes
1.47 + # only.
1.48
1.49 - # Permit assignment to instance attributes
1.50 - # only.
1.51 + if not (isinstance(parent, Class) and
1.52 + parent.instance_attributes().has_key(attrname)):
1.53
1.54 - if isinstance(parent, Class) and \
1.55 - not parent.instance_attributes().has_key(attrname):
1.56 + print >>sys.stderr, "Warning: potential assignment to instance attribute %s of %s not permitted" % (
1.57 + attrname, parent.full_name())
1.58
1.59 - parent.set(attrname, attrvalue, 0)
1.60 - else:
1.61 + # Assignment to a known attribute is permitted.
1.62 +
1.63 + elif parent.has_key(attrname):
1.64 for attrvalue in attrvalues:
1.65 parent.set(attrname, attrvalue, 0)
1.66
1.67 + # Assignment to an unknown attribute is not permitted.
1.68 +
1.69 + else:
1.70 + print >>sys.stderr, "Warning: potential assignment to static attribute %s of %s not permitted" % (
1.71 + attrname, parent.full_name())
1.72 +
1.73 # Visit attributes of objects known to be used.
1.74
1.75 if parentname in self.attributes_used: