1.1 --- a/micropython/deduce.py Fri Oct 11 11:40:31 2013 +0200
1.2 +++ b/micropython/deduce.py Sun Oct 13 15:45:26 2013 +0200
1.3 @@ -133,12 +133,37 @@
1.4 # Find instance attributes.
1.5
1.6 attr = unit.parent.instance_attributes().get(node.attrname)
1.7 + attrs = filter(None, [cls.instance_attributes().get(node.attrname) for cls in unit.parent.descendants])
1.8
1.9 - if attr:
1.10 + # A "leaf" class whose instances provide an attribute.
1.11 +
1.12 + if attr and not attrs:
1.13 node._access_type = "instance"
1.14 node._attr_deduced = attr
1.15 return
1.16
1.17 + # A class where instances of subclasses may provide an attribute.
1.18 +
1.19 + elif attrs:
1.20 + if attr:
1.21 + attrs.append(attr)
1.22 +
1.23 + node._attrs_deduced = [(a, a.get_value()) for a in attrs]
1.24 +
1.25 + # The instances may provide the attribute at the same position.
1.26 +
1.27 + positions = set([a.position for a in attrs])
1.28 + if len(positions) == 1:
1.29 + for position in positions:
1.30 + node._access_type = "positioned"
1.31 + node._position_deduced = position
1.32 + return
1.33 +
1.34 + # Otherwise, accessing the attributes is more work.
1.35 +
1.36 + node._access_type = "instance"
1.37 + return
1.38 +
1.39 # Find class attributes.
1.40 # The context will be overridden for compatible class attributes
1.41 # only.