# HG changeset patch # User Paul Boddie # Date 1338765639 -7200 # Node ID 1114731b6e1e70e12f3923e4e21ca15cd99e9071 # Parent 814bd122d84d5bdcdb96fdba004e3ebd8879de7e Simplify attribute assignment by insisting on the types identified from usage observations, only noting assignments on those and not on any type that could support a particular attribute. diff -r 814bd122d84d -r 1114731b6e1e micropython/__init__.py --- a/micropython/__init__.py Mon Jun 04 01:03:02 2012 +0200 +++ b/micropython/__init__.py Mon Jun 04 01:20:39 2012 +0200 @@ -728,10 +728,19 @@ # properly collect usage from it. parent = attr.parent + + # NOTE: At this point, parent should never be None. + if parent is None: continue + + # Instances provide the same identity as the object name. + elif isinstance(parent, Instance): parentname = objname + + # In general, the fully qualified name is obtained. + else: parentname = parent.full_name() @@ -739,31 +748,37 @@ if attrvalues: - # Instance-related accesses may involve any type - # supporting the attribute. - # NOTE: Here, an instance actually represents any kind - # NOTE: of object. + # NOTE: Here, an instance can actually represent any + # NOTE: kind of object. if isinstance(parent, Instance): - for attrvalue in attrvalues: - for name in objtable.any_possible_objects([attrname]): + + # Get the parent object using the special + # table entry. - # Get the parent object using the special - # table entry. + parent = objtable.access(objname, "#" + objname) - parent = objtable.access(name, "#" + name) + # Permit assignment to known instance attributes + # only. - # Permit assignment to instance attributes - # only. + if not (isinstance(parent, Class) and + parent.instance_attributes().has_key(attrname)): - if isinstance(parent, Class) and \ - not parent.instance_attributes().has_key(attrname): + print >>sys.stderr, "Warning: potential assignment to instance attribute %s of %s not permitted" % ( + attrname, parent.full_name()) - parent.set(attrname, attrvalue, 0) - else: + # Assignment to a known attribute is permitted. + + elif parent.has_key(attrname): for attrvalue in attrvalues: parent.set(attrname, attrvalue, 0) + # Assignment to an unknown attribute is not permitted. + + else: + print >>sys.stderr, "Warning: potential assignment to static attribute %s of %s not permitted" % ( + attrname, parent.full_name()) + # Visit attributes of objects known to be used. if parentname in self.attributes_used: