[Twisted-Python] Why do I get a _Dereference instance?

Patrik Blommaskog pb_twisted at olga.mine.nu
Sun Jul 6 18:20:32 EDT 2003


> > I am sure there is a logic to this, which I'd be grateful if someone
> > would like to explain to me or, better yet, point me to some nice
> > bedtime reading on the subject.
>
> Sounds like a bug, actually :)

Ouch, that is not what I wanted to hear. I experimented with it a bit
further by mutating the duck pond example, and found that:

	def setCopyableState(self, state):
	    self.__dict__.update(state)

gives the strange behavior:

	{'pond': <twisted.persisted.crefutil._Dereference instance at 0x009A1CE8>,
'broker': <twisted.spread.pb.Broker instance at 0x009AD1B0>, 'luid': 2}


While:
	def setCopyableState(self, state):
	    self.__dict__ = state

Gives the expected:

	{'pond': <cache_classes.SlaveDuckPond instance at 0x009AD8E8>, 'broker':
<twisted.spread.pb.Broker instance at 0x009AD450>, 'luid': 2}



Also, we have the peculiar case:

	def setCopyableState(self, state):
	    self.__dict__.update(state)
	    self.foo = state

Which gives:

	{'pond': <twisted.persisted.crefutil._Dereference instance at 0x009B5ED8>,
'foo': {'pond': <cache_classes.SlaveDuckPond instance at 0x009AD808>},
'broker': <twisted.spread.pb.Broker instance at 0x009AD1B0>, 'luid': 2}

So the item in 'foo' is dereferenced as expected, while __dict__["pond"] is
not. Go figure!


This feels like the twilight zone. Can somebody please tell me what is going
on? I have attached the code for my experiment.


- Patrik
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cache_classes.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030707/e0db713e/attachment.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cache_receiver.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030707/e0db713e/attachment-0001.txt 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cache_sender.py
Url: http://twistedmatrix.com/pipermail/twisted-python/attachments/20030707/e0db713e/attachment-0002.txt 


More information about the Twisted-Python mailing list