[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] ABC issues
From:       "Guido van Rossum" <guido () python ! org>
Date:       2008-05-27 19:39:45
Message-ID: ca471dc20805271239n40fd84e4x924d8e7ce163b2e4 () mail ! gmail ! com
[Download RAW message or body]

On Tue, May 27, 2008 at 12:16 PM, Armin Ronacher
<armin.ronacher@active-4.com> wrote:
> Hi,
>
> Guido van Rossum <guido <at> python.org> writes:
>
>> There's no need to register as Sized -- the Sized ABC recognizes
>> classes that define __len__ automatically. The Container class does
>> the same looking for __contains__. Since the deque class doesn't
>> implement __contains__, it is not considered a Container -- correctly
>> IMO.
> True.  deque doesn't implement __contains__.  However "in" still works
> because of the __iter__ fallback.

Sure, but that fallback is slow, and intentionally does not trigger
the 'Container' ABC.

> So from the API's perspective it's
> still compatible, even though it doesn't implement it.  The same probably
> affects old style iterators (__getitem__ with index).  One could argue that
> they are still iterable or containers, but that's harder to check so
> probably not worth the effort.

The ABCs do not intend to capture partial behavioral compatibility
that way -- the intent is to capture interface (in the duck typing
sense). Whether __iter__ is a good enough substitute for __contains__
depends on a lot of things -- surely for a huge list it isn't, and for
an iterator it isn't either (since it modifies the iterator's state).

>> >> Another issue is that builtin types don't accept ABCs currently.  For
>> >> example
>> >> set() | SomeSet() gives a TypeError, SomeSet() | set() however works.
>> >
>> > Pandora's Box -- sure you want to open it?
>>
>> In 3.0 I'd like to; this was my original intent. In 2.6 I think it's
>> not worth the complexity, though I won't complain.
> I would love to help on that as I'm very interested in that feature.

Please do submit patches!

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic