class Strange: def __hash__(self): return hash('hello') def __eq__(self, other): x.__dict__ = {} return False class X(object): pass v = 123 x = X() x.__dict__ = {Strange(): 42, 'hello': v+456} print x.hello