On Feb 14, 2008, at 6:22 PM, 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?

Yes.

Perhaps one could make __providedBy__ a
dynamic property or something?

Yes, although the ability to do so has led to memory leaks in some cases.

Or is this a very bad idea?  :)


I think it's a bad idea.  I'm not sure it is a "very" bad idea. :)

This falls in the category of deep magic. If you can find a way to solve your problem that doesn't involve deep magic, I would go with that. :)

FWIW, someday, I'm going to look at Python 3 ABCs. It appeared to me (the last time I paid attention) that Guido tried to accommodate zope.interface ideas to some degree. It appeared to me at the time that it would be possible to provide zope.interface in Python 3 building on ABCs in a way that preserved the most important semantics of zope.interface. I really need to do some prototyping to verify this -- but haven't been able to find time. ABC's wouldn't accommodate instance-specific declarations. If I could get most of what I want within the preferred Python architecture, I *think* I'd be willing to give up some of the dynamism we have now.

Jim

--
Jim Fulton
Zope Corporation


_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to