Python 3000 idea -- + on iterables -> itertools.chain

George Sakkis george.sakkis at gmail.com
Mon Nov 13 03:59:40 EST 2006


Fredrik Lundh wrote:

> George Sakkis wrote:
>
> > The base object class would be one candidate, similarly to the way
> > __nonzero__ is defined to use __len__, or __contains__ to use __iter__.
> >
> > Alternatively, iter() could be a wrapper type (or perhaps mixin)
> > instead of a function, something like:
>
> so you're proposing to either make *all* objects respond to "+", or
> introduce limited *iterator* algebra.

If by 'respond to "+"' is implied that you can get a "TypeError:
iterable argument required", as you get now for attempting "x in y" for
non-iterable y, why not ? Although I like the iterator algebra idea
better.

> not sure how that matches the OP's wish for "mostly backwards
> compatible" support for *iterable* algebra, really...

Given the subject of the thread, backwards compatibility is not the
main prerequisite. Besides, it's an *extension* idea; allow operations
that were not allowed before, not the other way around or modifying
existing semantics. Of course, programs that attempt forbidden
expressions on purpose so that they can catch and handle the exception
would break when suddenly no exception is raised, but I doubt there are
many of those...

George




More information about the Python-list mailing list