On Tue, May 12, 2009 at 1:39 PM, Terry Jones <te...@jon.es> wrote: > If Python allowed me to return a deferred from __init__, my problem would > vanish. That's not going to happen though, I know :-)
Well, if you /really/ want to, you can implement that; something like: #### from twisted.internet import defer class DeferredClass(object): def __new__(cls, *a, **kw): inst = super(DeferredClass, cls).__new__(cls, *a, **kw) return defer.maybeDeferred(inst.__init__, *a, **kw).addCallback(lambda ign: inst) #### Example usage: #### class Example(DeferredClass): def __init__(self, value): def _cb(value): self.value = value return defer.succeed(value).addCallback(_cb) def _printIt(x): print x.value Example(42).addCallback(_printIt) # Prints "42" #### Of course, this doesn't implement your magic wrapping behaviour, so maybe that's not what you meant. -- mithrandi, i Ainil en-Balandor, a faer Ambar _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python