[Python-Dev] ABC issues (original) (raw)

Guido van Rossum guido at python.org
Tue May 27 21:39:45 CEST 2008


On Tue, May 27, 2008 at 12:16 PM, Armin Ronacher <armin.ronacher at active-4.com> wrote:

Hi,

Guido van Rossum <guido 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/)



More information about the Python-Dev mailing list