'Disable selection options of attribute combinations that do not result in a variant'

def set_disabled_attributes(self, context):

    if ((not self.attributes) or (not self.has_variants)):
        return
    context.disabled_attributes = {}
    attributes = [attr.attribute for attr in self.attributes]
    def find_variant(combination):
        for variant in context.variants:
            if (len(variant.attributes) < len(attributes)):
                continue
            if (u'combination' not in variant):
                ref_combination = []
                for attr in variant.attributes:
                    idx = attributes.index(attr.attribute)
                    ref_combination.insert(idx, attr.attribute_value)
                variant[u'combination'] = ref_combination
            if (not (set(combination) - set(variant[u'combination']))):
                return True
    for (i, attr) in enumerate(self.attributes):
        if (i == 0):
            continue
        combination_source = []
        for prev_attr in self.attributes[:i]:
            combination_source.append([context.selected_attributes.get(prev_attr.attribute)])
        combination_source.append(context.attribute_values[attr.attribute])
        for combination in itertools.product(*combination_source):
            if (not find_variant(combination)):
                context.disabled_attributes.setdefault(attr.attribute, []).append(combination[(-1)])
