[PEAK] protocols question

Vladimir Iliev vladimir.iliev at gmail.com
Tue Feb 21 05:29:53 EST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Phillip J. Eby wrote:
> At 05:40 PM 02/17/2006 +0200, Vladimir Iliev wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>> zope.interface's interfaces has isOrExtends() method. Is there such
>> thing in PyProtocols?
>
> I don't remember; I've not needed such a thing to my recollection.
> PyProtocols doesn't pay attention to extending; it pays attention to
> *implication* (which can only be done in Zope via extending).
>
> My guess is that if you *need* to know this, you're doing something
> wrong.  The whole point of PyProtocols is to not need to know stuff
> like that; the system knows and takes care of it for you.
> Introspection is evil.  Code should be written so it doesn't care
> what interface something has: just adapt to the interface you
> *want*, and forget about it.
>
> (If you really really need to know this, Protocol objects have a
> getImpliedInterfaces() method and you can look if something's in it,
> but it's going to be dog-slow because it wasn't designed for this;
> it's designed to adapt things fast, not to do introspection, which
> as I said, is evil.  :) )
>
>
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.

Thanks anyway!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFD+uuhGtJoeXMSbC0RAsBWAJ4hQ8VW3w/25+O2J00jw0p5pzhlUwCeM0wN
8AFiizXXgaEGDp+RHiBwc+A=
=+Fjr
-----END PGP SIGNATURE-----




More information about the PEAK mailing list