On 5/11/07, Guido van Rossum <[EMAIL PROTECTED]> 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.)

Given:

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

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

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

>>> 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
useless.

Collin Winter
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to