[Python-3000] Discussions with no PEPs

Thomas Wouters thomas at python.org
Mon Mar 12 18:02:22 CET 2007


On 3/8/07, Bill Janssen <janssen at parc.com> wrote:

> There's an incomplete wiki page about a possible factoring of types at
> http://wiki.python.org/moin/AbstractBaseClasses.


The one thing that I have been unable to figure out (from that page, the
python-dev/python-3000 messages on the subject and talking with Guido) is
why ABCs are better than explicit interfaces like Twisted and Zope use. I
think mixing in abstract baseclasses in the normal inheritance tree is a
mistake, and if you have a separate tree, you really just have interfaces. I
can think of a half dozen nagging warts that will pop up with using ABCs
instead of interfaces, most of which I already griped to Guido about (but
failed to convince him.)

 - You can't take a third-party object, not participating in the
ABC/interface craze, and say 'it inherits from this ABC' (which you can do
for interfaces.)
 - If the abstract classes hold actual attributes (as is the suggestion, as
far as I can tell) rather than be completely empty, they can end up in the
middle of the inheritance tree and mess up MRO.
 - If the abstract classes are really completely empty, you need another
mechanism for figuring out what a particular abstract class entails.
 - You can't define *any* 'magic' on the abstract classes, things that are
supposed to work on ABCs only, because any inherited class will of course
automatically inherit the magic. If you use a magic metaclass for ABCs that
works around that, people 'implementing' classes with their own metaclass
will have to remember to subclass their metaclass from the
ABC-magic-metaclass.
 - Because of the no-magic thing, you can't have the ABC do useful things,
like asking it to verify if an implementation class has the right attributes
or whether it can find an adapter for one ABC to another.
 - You can't un-inherit an ABC, ever. You can't inherit from a particular
class to get some free implementation, but provide a slightly different
(conflicting) interface. (Alright, probably not realistically a problem, but
still.)
 - Mixing interface-definition and implementation like that makes it hard
for new programmers to pick up the difference. It will be harder to explain
the difference between 'dict' and 'Mapping' when they are both in the list
of bases. How can you tell one from the other?

As far as I can see, there is tremendously little difference between ABCs
and interfaces, at least the way Guido explained his ideas for ABCs to me.
The entirely Wiki page can be turned into a list of interfaces with a few
textual edits. The only difference is that ABCs nestle in the normal MRO,
which, in my eyes, is not a benefit at all. So... what's the actual benefit
of ABCs over interfaces?

-- 
Thomas Wouters <thomas at python.org>

Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-3000/attachments/20070312/65c98503/attachment.html 


More information about the Python-3000 mailing list