[Python-ideas] ABCs : adding an implements alias ?

Tarek Ziadé ziade.tarek at gmail.com
Sat Feb 21 15:40:37 CET 2009


Hello

I am playing with ABCs and I don't find the usage of the built-in
issubclass() natural to test wheter a class implements an ABC.

I think it's just the name of the built-in, or maybe the fact that it
is hidden in the mro. (or maybe because I have used zope.interfaces a
lot).

What about introducing two aliases ?

- implements, that points to issubclass
- implemented_by, that points to __subclasshook__

So we could write things like :

>>> from collections import Sized
>>> implements(list, Sized)
True
>>> Sized.implemented_by(list)
True

Instead of:

>>> from collections import Sized
>>> issubclass(list, Sized)
True
>>> Sized.__subclasshook__(list)   # mmm, maybe no one would write this..
True

Regards
Tarek

-- 
Tarek Ziadé | Association AfPy | www.afpy.org
Blog FR | http://programmation-python.org
Blog EN | http://tarekziade.wordpress.com/



More information about the Python-ideas mailing list