[Python-ideas] How assignment should work with generators?
Steven D'Aprano
steve at pearwood.info
Wed Nov 29 22:55:01 EST 2017
On Thu, Nov 30, 2017 at 10:49:19AM +1300, Greg Ewing wrote:
> C Anthony Risinger wrote:
> >Is __len__ a viable option now that __length_hint__ has been identified
> >for hints?
>
> No, I misremembered that feature, sorry.
>
> But I still don't like the idea of changing behaviour
> depending on whether the RHS "looks like" an iterator
> or not.
The reason I oppose that is that in all other ways related to iteration,
iterators are a perfect substitute for any other iterable:
for x in iterable: pass
list(iterable)
function(*iterable)
a, *b, c = iterable
a, *b = iterable
all behave identically whether iterable is a list or an iterator. This
would make the last example, and only that, behave differently depending
on whether you pass an iterator or some other iterable.
--
Steve
More information about the Python-ideas
mailing list