[Grok-dev] Does it make sense: registering factories that are functions not classes

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Jan 25 07:36:37 EST 2007


Hi,


In Grok we can do this:

class Foo(grok.Adapter):
    grok.context(...)
    grok.implements(...)
    grok.provides(...) # whenever implements is ambiguous
    ...

The Foo class now is a factory for the adapters. But there're
situations where you do not want a class, but just some function to be
the factory. So, would it make sense for Grok to allow for this
(thinking out loud now):

def foo_factory(...)
    grok.context(...)
    grok.implements(...)
    grok.provides(...) # whenever implements is ambiguous

    # and now follows the body of the factory function
    ...

Or maybe (I'm not even sure the previous example could work at all):

@grok.factory(context=..., implements=..., provides=....)
def foo_factory(...)
    # and now follows the body of the factory function
    ...

This could then of course be extended to work for multiadapters too.
Actually I now realise I came up for all of this, because I'd like to
register a *view* for IObject that will provide IInputWidget and is an
instance of ObjectWidget.

Since ObjectWidget needs more than just a context and a request for
__init__ arguments, I'd like to have a factory function that creates
the instance (the view) of ObjectWidget with whatever argument it
expects.

Does this make sense?


kind regards,
jw
-- 
Jan-Wijbrand Kolman


More information about the Grok-dev mailing list