[PEAK] protocols question

Vladimir Iliev vladimir.iliev at gmail.com
Tue Feb 21 12:02:05 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Phillip J. Eby wrote:
> 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.)
>
>
issubclass() will works, but if i use subclasses instead of instances,
i'm not aware of a way to implement the equivalent functionality of
advise(protocolIsSubsetOf=[...]). probably it's yagni but who knows ...
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFD+0eNGtJoeXMSbC0RAtZZAJ9hBFx4UEFaLkY47vfLa1/ngHLNfgCePGtH
wWg2OkpZg6rnrkw4TxHhklg=
=CJhl
-----END PGP SIGNATURE-----




More information about the PEAK mailing list