1.1 --- a/micropython/__init__.py Tue Jun 05 01:25:35 2012 +0200
1.2 +++ b/micropython/__init__.py Tue Jun 05 01:29:39 2012 +0200
1.3 @@ -656,7 +656,9 @@
1.4 # Using all attribute names for a particular name, attempt to get
1.5 # specific object types.
1.6
1.7 - all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name)
1.8 + all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name, True)
1.9 + if not all_objtypes:
1.10 + all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name, False)
1.11
1.12 # Where the name through which the attributes are accessed is the
1.13 # special "self" name, restrict the possibilities to types
2.1 --- a/micropython/common.py Tue Jun 05 01:25:35 2012 +0200
2.2 +++ b/micropython/common.py Tue Jun 05 01:29:39 2012 +0200
2.3 @@ -344,23 +344,33 @@
2.4
2.5 return hasattr(node, "unit") and node.unit.parent.has_key(node.unit.name)
2.6
2.7 -def get_object_types_for_usage(usage, objtable, name, unit_name):
2.8 +def get_object_types_for_usage(usage, objtable, name, unit_name, all_attributes):
2.9
2.10 """
2.11 Return for the given attribute 'usage', using the 'objtable', the object
2.12 types which satisfy such usage, reporting any problems for the given 'name'
2.13 and 'unit_name'. Each object type is given as a tuple of the form (type,
2.14 is_static).
2.15 +
2.16 + Where 'all_attributes' is set to a true value, all attributes in a usage
2.17 + list must be matched to provide object types. Otherwise, the presence of any
2.18 + attribute from a usage list in a type's set of attributes will be enough to
2.19 + provide that type as a suitable object type.
2.20 """
2.21
2.22 all_objtypes = set()
2.23
2.24 for attrnames in usage:
2.25 attrnames = attrnames or ()
2.26 - objtypes = objtable.all_possible_objects_plus_status(attrnames)
2.27 - if not objtypes:
2.28 - print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting all attributes %r" % (
2.29 - unit_name, name, attrnames.keys())
2.30 +
2.31 + # Determine whether all attributes are required.
2.32 +
2.33 + if all_attributes:
2.34 + objtypes = objtable.all_possible_objects_plus_status(attrnames)
2.35 + if not objtypes:
2.36 + print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting all attributes %r" % (
2.37 + unit_name, name, attrnames.keys())
2.38 + else:
2.39 objtypes = objtable.any_possible_objects_plus_status(attrnames)
2.40 if not objtypes:
2.41 print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting any attributes %r" % (
3.1 --- a/micropython/data.py Tue Jun 05 01:25:35 2012 +0200
3.2 +++ b/micropython/data.py Tue Jun 05 01:29:39 2012 +0200
3.3 @@ -477,7 +477,9 @@
3.4 attrtypes = {}
3.5 for name, combined_usage in usage.items():
3.6 if combined_usage is not None:
3.7 - objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name())
3.8 + objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name(), True)
3.9 + if not objtypes:
3.10 + objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name(), False)
3.11 if isinstance(self, Function) and self.is_method() and name == "self":
3.12 objtypes = filter_using_self(objtypes, self.parent)
3.13 attrtypes[name] = objtypes