# HG changeset patch # User Paul Boddie # Date 1351448501 -3600 # Node ID c97c8bec903022ec52ac22e5aa5f4bd59fc11cba # Parent af8a6a38eeede11a33768be0c1b97b6814f4a99e Changed the production of possible accessor types to choose between results from different assessment methods. diff -r af8a6a38eeed -r c97c8bec9030 micropython/common.py --- a/micropython/common.py Sun Oct 28 18:01:30 2012 +0100 +++ b/micropython/common.py Sun Oct 28 19:21:41 2012 +0100 @@ -74,7 +74,7 @@ general definition-based type observations. """ - target_names = set() + all_target_names = [] # Where an attribute could already be detected and where its nature is # not that of a general instance or an unresolved name, attempt to @@ -86,31 +86,39 @@ if isinstance(node._attr, Attr): attr = node._attr - target_names.add((attr.parent.full_name(), attr.is_static_attribute())) - return target_names + all_target_names.append(set([(attr.parent.full_name(), attr.is_static_attribute())])) # Otherwise, try and use an expression annotation. if isinstance(node, (AssAttr, Getattr)): expr = node._expr - if isinstance(expr, Attr) and expr.get_value(): - expr = expr.get_value() + # Permitting multiple expression types if they provide the + # attribute. + + if isinstance(expr, Attr): + exprs = expr.get_values() + elif expr: + exprs = [expr] + else: + exprs = None - if isinstance(expr, Class): - attr = expr.all_class_attributes().get(node.attrname) - elif isinstance(expr, Module): - attr = expr.get(node.attrname) - else: - attr = None + if exprs: + target_names = set() + + for expr in exprs: + attr = expr.get_static_attribute(node.attrname) - if attr: - target_names.add((attr.parent.full_name(), attr.is_static_attribute())) - return target_names + if attr: + target_names.add((attr.parent.full_name(), attr.is_static_attribute())) + + if target_names: + all_target_names.append(target_names) # Otherwise, attempt to employ the attribute usage observations. if node._attrusers: + target_names = set() # Visit each attribute user. @@ -127,7 +135,12 @@ for target_name, is_static in user._attrspecifictypes.get(node._username, []): target_names.add((target_name, is_static)) - return target_names + all_target_names.append(target_names) + + # Return the smallest set of target names. + + all_target_names.sort(key=lambda x: len(x)) + return all_target_names and all_target_names[0] def used_by_unit(node):