Behaviour-based interface/protocol implementation?

Daniel Urban urban.dani at gmail.com
Wed Jan 26 13:23:36 EST 2011


> That's just what I'd like and I suppose can't be currently done with
> current ABC, PyProtocols or zope.interface implementations, right?

It can. With __instancecheck__ you can override isinstance. It is
possible (for example) to write a subclass of abc.ABCMeta, which
extends __instancecheck__ to use an _instancehook classmethod
similarly to __subclasshook__. Then in your MyInterface class you can
implement _instancehook to check for methods/signatures/whatever you
want.


Daniel



More information about the Python-list mailing list