On 5/15/07, Collin Winter <[EMAIL PROTECTED]> wrote: > 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.)
Perhaps you tried it without the patch (reference [12] from PEP 3119) applied? It works for me: [EMAIL PROTECTED]:abc$ python3.0 Python 3.0x (p3yk, May 10 2007, 17:05:42) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import abc >>> isinstance((), abc.Sequence) True >>> > 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. The intention is that you shouldn't register such cases. This falls under the consenting-adults rule. -- --Guido van Rossum (home page: http://www.python.org/~guido/) _______________________________________________ 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
