[Zope3-Users] Re: Dynamic __providedBy__

Laurence Rowe l at lrowe.co.uk
Sat Feb 16 07:33:39 EST 2008


Martin Aspeli wrote:
> Hi!
> 
> I may have a use case where I need an instance to provide marker
> interfaces dynamically. That is, under certain conditions I want the
> type to say it provides a particular marker interface, and otherwise it
> doesn't. It still needs to support the usual by-class and
> directly-provided idioms for providing interfaces, including
> directlyProvides()/alsoProvides().
> 
> Is such a thing possible? Perhaps one could make __providedBy__ a
> dynamic property or something? Or is this a very bad idea?  :)

Instead of adding the magic to the class, maybe the framework could make 
the necessary *Provides calls when it adds context (aq wrapping) to the 
object? On traversal perhaps.

FWIW I do something similar with collective.tin to make `bare` 
SQLAlchemy mapped objects usable to me (this includes adding __name__, 
__parent__, aq wrapping and setting workflow permissions). I don't think 
  it is possible to achieve this in a __new__ method as there is no 
context available).

Laurence



More information about the Zope3-users mailing list