1.1 --- a/annotate.py Sun Jan 21 17:56:01 2007 +0100
1.2 +++ b/annotate.py Mon Jan 22 01:29:15 2007 +0100
1.3 @@ -5,7 +5,7 @@
1.4 which are produced when simplifying AST node trees originating from the compiler
1.5 module.
1.6
1.7 -Copyright (C) 2006 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This software is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU General Public License as
1.12 @@ -1416,34 +1416,6 @@
1.13 def __repr__(self):
1.14 return repr(self.names)
1.15
1.16 -class Attribute:
1.17 -
1.18 - """
1.19 - An attribute abstraction, indicating the type of the attribute along with
1.20 - its context or origin.
1.21 - """
1.22 -
1.23 - def __init__(self, context, type):
1.24 - self.context = context
1.25 - self.type = type
1.26 -
1.27 - def __eq__(self, other):
1.28 - return hasattr(other, "type") and other.type == self.type or other == self.type
1.29 -
1.30 - def __repr__(self):
1.31 - return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
1.32 -
1.33 -class Self:
1.34 -
1.35 - """
1.36 - A program node encapsulating object/context information in an argument list.
1.37 - This is not particularly like Attribute, Class, Instance or other such
1.38 - things, since it actually appears in the program representation.
1.39 - """
1.40 -
1.41 - def __init__(self, attribute):
1.42 - self.types = [attribute]
1.43 -
1.44 class Importer:
1.45
1.46 "An import machine, searching for and loading modules."
1.47 @@ -1654,10 +1626,19 @@
1.48 structure = structure.type
1.49 results = []
1.50 for attribute, accessor in find_attributes(structure, name):
1.51 +
1.52 + # Detect class attribute access via instances.
1.53 +
1.54 + if attribute is not None and isinstance(structure, Instance) and isinstance(accessor, Class):
1.55 + attribute = accessor.get_attribute_for_instance(attribute, structure)
1.56 +
1.57 + # Produce an attribute with the appropriate context.
1.58 +
1.59 if attribute is not None and isinstance(structure, Structure):
1.60 results.append((Attribute(structure, attribute.type), accessor))
1.61 else:
1.62 results.append((attribute, accessor))
1.63 +
1.64 return results
1.65
1.66 # Convenience functions.