[Python-ideas] Generator unpacking

Rob Cliffe rob.cliffe at btinternet.com
Mon Feb 15 22:47:14 EST 2016



On 15/02/2016 23:54, Andrew Barnert via Python-ideas wrote:
> On Feb 15, 2016, at 14:41, Brendan Barnwell <brenbarn at brenbarn.net> wrote:
>>> On 2016-02-15 14:27, Andrew Barnert wrote:
>>> Of course any useful definition would leave pathological types that
>>> are neither iterator nor collection (e.g., an object that returns a
>>> new iterator each time, but those iterators destructively modify
>>> self), or maybe where they do qualify but misleadingly so (I can't
>>> think of any examples). And there may also be cases where it isn't
>>> clear (e.g., is a collection of shared memory not a collection
>>> because some other process can change its values, or does that count
>>> as "unless mutated"? that probably depends on how and why your app is
>>> using that shared memory). But that isn't a problem; we're not trying
>>> to come up with a definition that could be used to write
>>> type-theoretic behavior proofs for Python semantics, but something
>>> that's useful in practice for discussing almost all real Python
>>> programs with other humans.
>> <snip>
>>> Because iterators and collections are
>>> both iterable, just knowing that something is an iterable doesn't
>>> tell you whether it's reusable. But knowing that something is a
>>> collection (assuming we have a well-defined term "collection") would.
>>> Which is exactly the point of the proposal.
>>     I still don't understand why you want to use the term "collection" when everything you say about the purpose of the term (as for instance your last paragraph here) suggests you want to know whether it is reusable. To ordinary humans "collection" says nothing about iteration or reusability.
> First, the word "reiterable" is acceptable to me (and certainly better than not having any such term)--that's why I said "like 'reiterable' or 'collection'" multiple times. It's an easy-to-remember term, and it's name helps keep it straight. The biggest problem is that it's not an actual word, and it looks and sounds ugly. It's much better than not having a word at all, and forcing people to use phrases like "reusable non-iterator iterable", but it's not ideal.
>
> The reason "collection" is better is that it matches an intuitive category that actually means what we want.
>
> And the fact that it's not*immediately obvious*  [my emphasis - RC] that it does what we want is a _good_ thing, because it means people have one simple thing to learn and remember: you can iterate collections over and over without affecting them.
So you'd rather people learned the word "collection" (which does not 
convey that they are reiterable) and then *learned* that collections can 
be iterated over repeatedly, than learn the word "reiterable" that makes 
it *immediately obvious* that something can be iterated over repeatedly.
Why make life more difficult?  How is that a "_good_ thing"?
Rob Cliffe
>
> And "collection" stays intuitive when used in compounds like "virtual collection" or "lazy collection" or "infinite collection". So, I can say, "a range is a lazy collection", and you know that means it's not a one-shot iterator, because collections aren't one-shot iterators--"lazy" ones, don't physically hold the stuff, but come up with it when asked, but they're still collections, so they're still not one-shot iterators.
>
> Also, notice that we already to use the term "collection" informally to mean exactly what people intuitively think of--including in the documentation of the "collections" module in the stdlib. We certainly don't use the term "reiterable" anywhere (especially when typing with autocorrect on).
>
> I think people worry about the case of things that aren't collections but also aren't iterators. But let's look at one:
>
>      class Random3to6d6:
>          def __iter__(self):
>              for _ in range(randint(3, 6)):
>                  yield randint(1, 6)
>
> That's clearly not a collection. It's also clearly not an iterator. So, if I want to use it, that's a clear sign that I have to think about it carefully.
>
> Is it a reusable or a reiterable? Depends how you define the term. Which means I have to know, and have internalized, the exact definition before "reusable" is any help here. I still have to think about it carefully, but it's less obvious that I have to do so.
>
> Again, I think adding "reiterable" to the glossary (and maybe collections.abc and typing) would be a big improvement; I just think adding "collection" would be a slightly better one.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160216/3ca4caab/attachment.html>


More information about the Python-ideas mailing list