def ref(self, key): try: hash(key) except TypeError: return self._iddict, Hashable(key) # key is not hashable try: weakref.ref(key) except TypeError: return self._regdict, key # key cannot be weakly ref'ed else: return self._weakdict, key # normal case
def see_instance(self, x): assert isinstance(x, self.classdesc.pyobj) key = Hashable(x) if key in self.instances_seen: return self.instances_seen.add(key) self.bookkeeper.event('mutable', x) source = InstanceSource(self.bookkeeper, x) def delayed(): for attr in source.all_instance_attributes(): self.add_source_for_attribute(attr, source) # ^^^ can trigger reflowing self._see_instance_flattenrec(delayed)
def __init__(self, value, concretetype=None): Hashable.__init__(self, value) if concretetype is not None: self.concretetype = concretetype
def __hash__(self): return hash((self.__class__, self.type, Hashable(self.instance)))