def _true_getattr(self, attr): if attr == '__class__': return self.classdef.read_attr__class__() attrdef = self.classdef.find_attribute(attr) position = getbookkeeper().position_key attrdef.read_locations[position] = True s_result = attrdef.getvalue() # hack: if s_result is a set of methods, discard the ones # that can't possibly apply to an instance of self.classdef. # XXX do it more nicely if isinstance(s_result, SomePBC): s_result = self.classdef.lookup_filter(s_result, attr, self.flags) elif isinstance(s_result, SomeImpossibleValue): self.classdef.check_missing_attribute_update(attr) # blocking is harmless if the attribute is explicitly listed # in the class or a parent class. for basedef in self.classdef.getmro(): if basedef.classdesc.all_enforced_attrs is not None: if attr in basedef.classdesc.all_enforced_attrs: raise HarmlesslyBlocked("get enforced attr") elif isinstance(s_result, SomeList): s_result = self.classdef.classdesc.maybe_return_immutable_list( attr, s_result) return s_result
def s_getattr(self, attrname, flags): attrdef = self.find_attribute(attrname) s_result = attrdef.s_value # hack: if s_result is a set of methods, discard the ones # that can't possibly apply to an instance of self. # XXX do it more nicely if isinstance(s_result, SomePBC): s_result = self.lookup_filter(s_result, attrname, flags) elif isinstance(s_result, SomeImpossibleValue): self.check_missing_attribute_update(attrname) # blocking is harmless if the attribute is explicitly listed # in the class or a parent class. for basedef in self.getmro(): if basedef.classdesc.all_enforced_attrs is not None: if attrname in basedef.classdesc.all_enforced_attrs: raise HarmlesslyBlocked("get enforced attr") elif isinstance(s_result, SomeList): s_result = self.classdesc.maybe_return_immutable_list( attrname, s_result) return s_result
def pbc_getattr(self, pbc, s_attr): assert s_attr.is_constant() attr = s_attr.const descs = list(pbc.descriptions) first = descs[0] if len(descs) == 1: return first.s_read_attribute(attr) change = first.mergeattrfamilies(descs[1:], attr) attrfamily = first.getattrfamily(attr) position = self.position_key attrfamily.read_locations[position] = True actuals = [] for desc in descs: actuals.append(desc.s_read_attribute(attr)) s_result = unionof(*actuals) s_oldvalue = attrfamily.get_s_value(attr) attrfamily.set_s_value(attr, unionof(s_result, s_oldvalue)) if change: for position in attrfamily.read_locations: self.annotator.reflowfromposition(position) if isinstance(s_result, SomeImpossibleValue): for desc in descs: try: attrs = desc.read_attribute('_attrs_') except AttributeError: continue if isinstance(attrs, Constant): attrs = attrs.value if attr in attrs: raise HarmlesslyBlocked("getattr on enforced attr") return s_result