Does Class implements Interface?

Jonathan Gardner jgardner at jonathangardner.net
Thu Aug 27 16:42:18 EDT 2009


On Aug 27, 6:16 am, "Emanuele D'Arrigo" <man... at gmail.com> wrote:
> Greetings everybody,
>
> let's say I have a Class C and I'd like to verify if it implements
> Interface I. If I is available to me as a class object I can use
> issubclass(C, I) and I can at least verify that I is a superclass of
> C. There are a couple of issues with this approach however:
>
> 1) C might override not just I's methods code but also I's methods
> signatures, effectively changing the interface.
> 2) What if I is -not- available to me as the superclass of C but as a
> description of the interface, i.e. as an IDL(*) file?
>
> Are there resources such as tools, recipes, documents or strategies
> that could help me deal with these issues? I've already looked into
> the ABC module and the zope.interface. I'm just fishing for more
> things to look at.
>

Have you heard of duck typing?

Ignore all those things and rely on human (aka natural language)
documentation. That is, if you want to see if a class will work for an
interface, go read the docs on the interface (or rather, what the
function expects the interface to be) and what the class provides and
see if they fit.




More information about the Python-list mailing list