[Twisted-web] subtle copying in woven driving me crazy.

Douglas Bagnall twisted-web@twistedmatrix.com
Sun, 21 Dec 2003 22:04:53 +1300


I thought it was reasonable to give my player storing object a 
requestAvatarId method and call it a checker, and it seemed to work 
until it was found that new players couldn't log in.  Eventually I 
discovered that:

class Checker(dict):
     __implements__ = checkers.ICredentialsChecker
     def __init__(self):
         log.debug(id(self))
     def requestAvatarId(self, credentials):
         log.debug(id(self))

gives two different numbers.  Of course seperating the checker from the 
player model fixed this problem, and is no doubt correcter. Similarly:

class SomePage(page.Page):
     def __init__(self, children_dict):
         page.Page.__init__(self)
         self.children_dict = children_dict
         log.debug(id(self.children_dict))

     def getDynamicChild(self, path, request):
         log.debug(id(self.children_dict))
         return self.children_dict.get(path, error.NoResource())

gives two different id numbers!  So you can't manipulate the children by 
referring to the original dictionary in some other context.  Again, 
there is an easy way around this, once you realise what is happening, 
and that other way is perhaps better, but this has caused me some 
bewilderment.

Is this behaviour intentional? or necessary?  It should perhaps be 
better documented.


douglas