[Python-3000] Revised PEP 3119 (Abstract Base Classes)

Collin Winter collinw at gmail.com
Wed May 16 02:38:42 CEST 2007

On 5/11/07, Guido van Rossum <guido at python.org> wrote:
> - Overloading isinstance and issubclass is now a key mechanism rather
> than an afterthought; it is also the only change to C code required
> - Built-in (and user-defined) types can be registered as "virtual
> subclasses" (not related to virtual base classes in C++) of the
> standard ABCs, e.g. Sequence.register(tuple) makes issubclass(tuple,
> Sequence) true (but Sequence won't show up in __bases__ or __mro__).

(The bit about "issubclass(tuple, Sequence)" currently isn't true with
the sandbox prototype, but let's assume that it is/will be.)


class MyABC(metaclass=ABCMeta):
  def foo(self): # A concrete method
    return 5

class MyClass(MyABC): # Mark as implementing the ABC's interface

>>> a = MyClass()
>>> isinstance(a, MyABC)
True # Good, I can call foo()
>>> a.foo()

>>> MyABC.register(list)
>>> isinstance([], MyABC)
True # Good, I can call foo()
>>> [].foo()
Traceback (most recent call last):
AttributeError: 'list' object has no attribute 'foo'

Have I missed something? It would seem that when dealing with ABCs
that provide concrete methods, "isinstance(x, SomeABC) == True" is

Collin Winter

More information about the Python-3000 mailing list