1.1 --- a/micropython/common.py Mon Oct 24 23:57:02 2011 +0200
1.2 +++ b/micropython/common.py Mon Oct 31 19:09:47 2011 +0100
1.3 @@ -128,7 +128,10 @@
1.4
1.5 new_dict = {}
1.6 for key, value in d.items():
1.7 - new_dict[key] = set([value])
1.8 + if value is None:
1.9 + new_dict[key] = None
1.10 + else:
1.11 + new_dict[key] = set([value])
1.12 return new_dict
1.13
1.14 def merge_mapping_dicts(dicts):
1.15 @@ -145,10 +148,11 @@
1.16
1.17 for old_dict in dicts:
1.18 for key, value in old_dict.items():
1.19 - if not new_dict.has_key(key):
1.20 - new_dict[key] = ObjectSet(value)
1.21 - else:
1.22 - new_dict[key].update(value)
1.23 + if value is not None:
1.24 + if not new_dict.has_key(key):
1.25 + new_dict[key] = ObjectSet(value)
1.26 + else:
1.27 + new_dict[key].update(value)
1.28
1.29 def combine_mapping_dicts(d1, d2):
1.30
1.31 @@ -163,22 +167,31 @@
1.32 d1: {'a' : [{'f', 'g'}, {'f', 'h'}], ...}
1.33 d2: {'a' : [{'f'}, {'e', 'f', 'g'}], ...}
1.34 -> {'a' : [{'f', 'g'}, {'f', 'h'}, {'e', 'f', 'g'}, {'e', 'f', 'g', 'h'}], ...}
1.35 +
1.36 + Note that items of 'd2' whose keys are not in 'd1' are not added to 'd1'
1.37 + since this, in the context of propagating attribute usage observations,
1.38 + would result in spurious usage details being made available in places where
1.39 + the names may not have been defined.
1.40 """
1.41
1.42 - return combine(d1, d2, {}, combine_object_set_lists)
1.43 + return combine(d1, d2, {}, combine_object_set_lists, True)
1.44
1.45 -def combine(d1, d2, combined, combine_op):
1.46 +def combine(d1, d2, combined, combine_op, only_d1_keys=False):
1.47
1.48 """
1.49 Combine dictionaries 'd1' and 'd2' in the 'combined' object provided, using
1.50 the 'combine_op' to merge values from the dictionaries.
1.51 +
1.52 + If 'only_d1_keys' is set to a true value, items from 'd2' employing keys not
1.53 + in 'd1' will not be added to 'd1'.
1.54 """
1.55
1.56 d2_keys = d2.keys()
1.57
1.58 for key in d2_keys:
1.59 if not d1.has_key(key):
1.60 - combined[key] = d2[key]
1.61 + if not only_d1_keys:
1.62 + combined[key] = d2[key]
1.63 else:
1.64 combined[key] = combine_op(d1[key], d2[key])
1.65
1.66 @@ -195,6 +208,14 @@
1.67 members.
1.68 """
1.69
1.70 + if l1 is None:
1.71 + if l2 is None:
1.72 + return None
1.73 + else:
1.74 + return l2
1.75 + elif l2 is None:
1.76 + return l1
1.77 +
1.78 combined = set([])
1.79 for i1 in l1:
1.80 for i2 in l2: