# HG changeset patch # User Paul Boddie # Date 1338767455 -7200 # Node ID 57d6f164821b05a1d9441b1b1edbc0803d727c4d # Parent 1af8032d9f883bec8f4afac0a5484636864e5d87 Moved the code for class hierarchy filtering of types into a common function. Introduced type filtering in the attribute usage type deduction method. diff -r 1af8032d9f88 -r 57d6f164821b micropython/__init__.py --- a/micropython/__init__.py Mon Jun 04 01:38:25 2012 +0200 +++ b/micropython/__init__.py Mon Jun 04 01:50:55 2012 +0200 @@ -664,11 +664,7 @@ if name == "self" and user and user.unit and user.unit.is_method(): cls = user.unit.parent - descendants = cls.all_descendants() - valid_objtypes = [] - for objname, is_static in all_objtypes: - if objname == cls.full_name() or objname in descendants: - valid_objtypes.append((objname, is_static)) + valid_objtypes = filter_using_self(all_objtypes, cls) else: valid_objtypes = all_objtypes diff -r 1af8032d9f88 -r 57d6f164821b micropython/common.py --- a/micropython/common.py Mon Jun 04 01:38:25 2012 +0200 +++ b/micropython/common.py Mon Jun 04 01:50:55 2012 +0200 @@ -370,6 +370,21 @@ return all_objtypes +def filter_using_self(objtypes, cls): + + """ + Filter the given 'objtypes' (a collection of object names and static + indicators) for the given 'cls', returning only the (name, static) elements + compatible with 'cls' and its descendants. + """ + + descendants = cls.all_descendants() + filtered = [] + for objname, is_static in objtypes: + if objname == cls.full_name() or objname in descendants: + filtered.append((objname, is_static)) + return filtered + # Errors. class ProcessingError(Exception): diff -r 1af8032d9f88 -r 57d6f164821b micropython/data.py --- a/micropython/data.py Mon Jun 04 01:38:25 2012 +0200 +++ b/micropython/data.py Mon Jun 04 01:50:55 2012 +0200 @@ -477,7 +477,10 @@ attrtypes = {} for name, combined_usage in usage.items(): if combined_usage is not None: - attrtypes[name] = get_object_types_for_usage(combined_usage, objtable, name, self.full_name()) + objtypes = get_object_types_for_usage(combined_usage, objtable, name, self.full_name()) + if isinstance(self, Function) and self.is_method() and name == "self": + objtypes = filter_using_self(objtypes, self.parent) + attrtypes[name] = objtypes return attrtypes def set_contributors(self, node):