1.1 --- a/micropython/common.py Sun Oct 28 18:01:30 2012 +0100
1.2 +++ b/micropython/common.py Sun Oct 28 19:21:41 2012 +0100
1.3 @@ -74,7 +74,7 @@
1.4 general definition-based type observations.
1.5 """
1.6
1.7 - target_names = set()
1.8 + all_target_names = []
1.9
1.10 # Where an attribute could already be detected and where its nature is
1.11 # not that of a general instance or an unresolved name, attempt to
1.12 @@ -86,31 +86,39 @@
1.13
1.14 if isinstance(node._attr, Attr):
1.15 attr = node._attr
1.16 - target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
1.17 - return target_names
1.18 + all_target_names.append(set([(attr.parent.full_name(), attr.is_static_attribute())]))
1.19
1.20 # Otherwise, try and use an expression annotation.
1.21
1.22 if isinstance(node, (AssAttr, Getattr)):
1.23 expr = node._expr
1.24
1.25 - if isinstance(expr, Attr) and expr.get_value():
1.26 - expr = expr.get_value()
1.27 + # Permitting multiple expression types if they provide the
1.28 + # attribute.
1.29 +
1.30 + if isinstance(expr, Attr):
1.31 + exprs = expr.get_values()
1.32 + elif expr:
1.33 + exprs = [expr]
1.34 + else:
1.35 + exprs = None
1.36
1.37 - if isinstance(expr, Class):
1.38 - attr = expr.all_class_attributes().get(node.attrname)
1.39 - elif isinstance(expr, Module):
1.40 - attr = expr.get(node.attrname)
1.41 - else:
1.42 - attr = None
1.43 + if exprs:
1.44 + target_names = set()
1.45 +
1.46 + for expr in exprs:
1.47 + attr = expr.get_static_attribute(node.attrname)
1.48
1.49 - if attr:
1.50 - target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
1.51 - return target_names
1.52 + if attr:
1.53 + target_names.add((attr.parent.full_name(), attr.is_static_attribute()))
1.54 +
1.55 + if target_names:
1.56 + all_target_names.append(target_names)
1.57
1.58 # Otherwise, attempt to employ the attribute usage observations.
1.59
1.60 if node._attrusers:
1.61 + target_names = set()
1.62
1.63 # Visit each attribute user.
1.64
1.65 @@ -127,7 +135,12 @@
1.66 for target_name, is_static in user._attrspecifictypes.get(node._username, []):
1.67 target_names.add((target_name, is_static))
1.68
1.69 - return target_names
1.70 + all_target_names.append(target_names)
1.71 +
1.72 + # Return the smallest set of target names.
1.73 +
1.74 + all_target_names.sort(key=lambda x: len(x))
1.75 + return all_target_names and all_target_names[0]
1.76
1.77 def used_by_unit(node):
1.78