[PEAK] protocols question

Phillip J. Eby pje at telecommunity.com
Tue Feb 21 11:33:37 EST 2006


At 12:29 PM 2/21/2006 +0200, Vladimir Iliev wrote:
>I was wondering if something like that is possible:
>
>@dispatch.generic()
>def getSomething(tag,**k): pass
>
>def registerSomething(factory, tag_):
>     @getSomething.when('tag_.isOrExtends(tag)')
>     def getSomething(tag,**k):
>         return factory(**k)
>
>I thought of abusing interfaces as tags, because of their implication
>features, but looks like it's bad idea. I'll just implement my own tag
>class.

Well, if it's PyProtocols interfaces, keep in mind that they are also 
classes, so 'issubclass(tag_,tag)' would work for the example 
above.  Unfortunately, that's not an indexable expression since 'tag' is 
not a constant.  (Unless of course your example is backwards from the way I 
think.)




More information about the PEAK mailing list