[PEAK] I don't understand uponAssembly()

Doug Quale quale1 at charter.net
Thu Mar 24 16:20:14 EST 2005

John Landahl <john at landahl.org> writes:

> Doug Quale wrote:
> > but I don't understand how this works.
> >     >>> class k(binding.Component):
> >     ...     def uponAssembly(self):
> >     ...         print 'assembling %r' % self
> >     ...
> This is not how uponAssembly works, as far as I know.  It is typically
> used in a property constructor, like so:
>  >>> class Foo(binding.Component):
> ...     def bar(self):
> ...         print "hello world"
> ...     bar = binding.Make(bar, uponAssembly=True)
> ...
>  >>> f = Foo(config.makeRoot())
> hello world
> What is it you're trying to do?

I want to run some initialization when the component instance is
created.  (The components are controllers for GUI views.)  Normally
that would be done in __init__(), but peak largely removes the need to
code __init__, and for that I'm grateful.

I see now that the peak api docs warn not to override uponAssembly(),
which means that I did a very poor job in trying to figure this out.
The construction you demonstrate should do exactly what I need.

class k(binding.Component):
    def _my_init(self):
    _my_init = binding.Make(_my_init, uponAssembly=True)

I was a bit afraid that my misunderstanding would be about an
embarrassingly simple point, but I'm pleased that it's easy to get the
behavior I want.  I searched the mailing list archives (google using
site:peak.telecomunity.com is a great tool) and I see now that the
answer was there, but I failed to make the connection.  There was some
discussion about starting services upon instance construction using
uponAssembly=True bindings.

Thanks for your help.

More information about the PEAK mailing list