micropython

Changeset

466:3a679e21fb5a
2011-09-05 Paul Boddie raw files shortlog changelog graph Added a restriction on the possible types involved where attributes are accessed via "self", using the parent class and its descendants to filter the deduced set of types.
micropython/__init__.py (file)
     1.1 --- a/micropython/__init__.py	Mon Sep 05 00:57:24 2011 +0200
     1.2 +++ b/micropython/__init__.py	Mon Sep 05 23:30:02 2011 +0200
     1.3 @@ -620,9 +620,23 @@
     1.4  
     1.5              all_objtypes = get_object_types_for_usage(usage, objtable, name, from_name)
     1.6  
     1.7 +            # Where the name through which the attributes are accessed is the
     1.8 +            # special "self" name, restrict the possibilities to types
     1.9 +            # appropriate for the method involved.
    1.10 +
    1.11 +            if name == "self" and user and user.unit and user.unit.is_method():
    1.12 +                cls = user.unit.parent
    1.13 +                descendants = cls.all_descendants()
    1.14 +                valid_objtypes = []
    1.15 +                for objname, is_static in all_objtypes:
    1.16 +                    if objname == cls.full_name() or objname in descendants:
    1.17 +                        valid_objtypes.append((objname, is_static))
    1.18 +            else:
    1.19 +                valid_objtypes = all_objtypes
    1.20 +
    1.21              # Investigate the object types.
    1.22  
    1.23 -            self._collect_attributes_for_types(from_name, objtable, all_objtypes, usage)
    1.24 +            self._collect_attributes_for_types(from_name, objtable, valid_objtypes, usage)
    1.25  
    1.26          # Get specific name references and visit the referenced objects.
    1.27