[Python-ideas] How assignment should work with generators?

Steven D'Aprano steve at pearwood.info
Tue Nov 28 01:31:51 EST 2017


On Tue, Nov 28, 2017 at 06:15:47PM +1300, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >How does "stop iterating here" equate to a wildcard?
> 
> The * means "I don't care what else the sequence has in it".
>
> Because I don't care, there's no need to iterate any further.

I'll grant you that. But I don't see how that relates to being a 
wildcard. I'm not seeing the connection. I mean, you wouldn't interpret

   from module import *

to mean "I don't care what's in the module, so don't bother importing 
anything" would you? So the concept of wildcard here seems to be the 
opposite to its use here:

- in imports, it means "import everything the module offers";
- in extended iterable unpacking, it means "collect everything";

both of which (to me) seem related to the concept of a wildcard; but in 
this proposed syntax, we have

   x, y, * = iterable

which means the opposite to "collect everything", instead meaning 
"collect nothing and stop".

Anyway, given that * = is visually ambiguous with *= I don't think this 
syntax is feasible (even though * = is currently a syntax error, or at 
least it is in 3.5).



-- 
Steve


More information about the Python-ideas mailing list