# HG changeset patch # User Paul Boddie # Date 1338852579 -7200 # Node ID deb3720de7d1a8c56e642524c08af862d4206a25 # Parent 18271fe1fd531bf7e99ccd9e4b7154e64da87ad4 Introduced more rigid selection of suitable types depending on whether all attributes given as being used can be found in one or more types, or whether the selection of less satisfactory types (supporting any of the attributes) is necessary. diff -r 18271fe1fd53 -r deb3720de7d1 micropython/__init__.py --- a/micropython/__init__.py Tue Jun 05 01:25:35 2012 +0200 +++ b/micropython/__init__.py Tue Jun 05 01:29:39 2012 +0200 @@ -656,7 +656,9 @@ # Using all attribute names for a particular name, attempt to get # specific object types. - all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name) + all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name, True) + if not all_objtypes: + all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name, False) # Where the name through which the attributes are accessed is the # special "self" name, restrict the possibilities to types diff -r 18271fe1fd53 -r deb3720de7d1 micropython/common.py --- a/micropython/common.py Tue Jun 05 01:25:35 2012 +0200 +++ b/micropython/common.py Tue Jun 05 01:29:39 2012 +0200 @@ -344,23 +344,33 @@ return hasattr(node, "unit") and node.unit.parent.has_key(node.unit.name) -def get_object_types_for_usage(usage, objtable, name, unit_name): +def get_object_types_for_usage(usage, objtable, name, unit_name, all_attributes): """ Return for the given attribute 'usage', using the 'objtable', the object types which satisfy such usage, reporting any problems for the given 'name' and 'unit_name'. Each object type is given as a tuple of the form (type, is_static). + + Where 'all_attributes' is set to a true value, all attributes in a usage + list must be matched to provide object types. Otherwise, the presence of any + attribute from a usage list in a type's set of attributes will be enough to + provide that type as a suitable object type. """ all_objtypes = set() for attrnames in usage: attrnames = attrnames or () - objtypes = objtable.all_possible_objects_plus_status(attrnames) - if not objtypes: - print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting all attributes %r" % ( - unit_name, name, attrnames.keys()) + + # Determine whether all attributes are required. + + if all_attributes: + objtypes = objtable.all_possible_objects_plus_status(attrnames) + if not objtypes: + print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting all attributes %r" % ( + unit_name, name, attrnames.keys()) + else: objtypes = objtable.any_possible_objects_plus_status(attrnames) if not objtypes: print >>sys.stderr, "Warning: usage in %r for %r finds no object supporting any attributes %r" % ( diff -r 18271fe1fd53 -r deb3720de7d1 micropython/data.py --- a/micropython/data.py Tue Jun 05 01:25:35 2012 +0200 +++ b/micropython/data.py Tue Jun 05 01:29:39 2012 +0200 @@ -477,7 +477,9 @@ attrtypes = {} for name, combined_usage in usage.items(): if combined_usage is not None: - objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name()) + objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name(), True) + if not objtypes: + objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name(), False) if isinstance(self, Function) and self.is_method() and name == "self": objtypes = filter_using_self(objtypes, self.parent) attrtypes[name] = objtypes