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

2017-12-02 Thread Greg Ewing
C Anthony Risinger wrote: * Unpacking is destructuring not pattern matching. We're just arguing about the definition of terms now. The point I was making is that unpacking is fundamentally a declarative construct, or at least that's how I think about it. I used the term "pattern matching" bec

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

2017-12-01 Thread C Anthony Risinger
On Nov 29, 2017 10:09 PM, "Steven D'Aprano" wrote: > On Thu, Nov 30, 2017 at 11:21:48AM +1300, Greg Ewing wrote: > > > It seems that many people think about unpacking rather > > differently from the way I do. I think the difference > > is procedural vs. declarative. > > > > To my way of thinking,

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

2017-12-01 Thread Paul Moore
On 1 December 2017 at 09:48, Kirill Balunov wrote: > Probably, some time ago it was necessary to split this thread into two > questions: > 1. Philosophical question regarding sequences and iterators. In particular, > should they behave differently depending on the context, > or, in other words, wh

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

2017-12-01 Thread Kirill Balunov
2017-11-29 22:33 GMT+03:00 Steve Barnes : > > Just a thought but what about a syntax something along the lines of: > > a, b, *remainder = iterable > > Where remainder becomes the iterable with the first two values consumed > by assigning to a & b. If the iterator has less than 2 values, (in the >

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

2017-11-30 Thread Greg Ewing
Steve Barnes wrote: Since the practical difference between remainder being the (partly exhausted) iterator and it being a list, (itself an iterator), A list is *not* an iterator, it's a sequence. There's a huge difference. Items of a sequence can be accessed at random, it can be iterated over

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

2017-11-30 Thread Steve Barnes
On 30/11/2017 22:26, Greg Ewing wrote: > Steven D'Aprano wrote: >> On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: >> >>> Just a thought but what about a syntax something along the lines of: >>> >>> a, b, *remainder = iterable >>> >>> Where remainder becomes the iterable with the fi

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

2017-11-30 Thread Greg Ewing
Steven D'Aprano wrote: On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: Just a thought but what about a syntax something along the lines of: a, b, *remainder = iterable Where remainder becomes the iterable with the first two values consumed by assigning to a & b. Guido's time

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

2017-11-30 Thread Paul Moore
On 30 November 2017 at 16:16, Steve Barnes wrote: > I had a sneaky feeling that it did, which raises the question of what > the bleep this enormous thread is about, since the fundamental syntax > currently exists Essentially, it's about the fact that to build remainder you need to copy all of

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

2017-11-30 Thread Steve Barnes
On 30/11/2017 15:50, Steven D'Aprano wrote: > On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: > >> Just a thought but what about a syntax something along the lines of: >> >> a, b, *remainder = iterable >> >> Where remainder becomes the iterable with the first two values consumed >>

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

2017-11-30 Thread Steven D'Aprano
On Wed, Nov 29, 2017 at 07:33:54PM +, Steve Barnes wrote: > Just a thought but what about a syntax something along the lines of: > > a, b, *remainder = iterable > > Where remainder becomes the iterable with the first two values consumed > by assigning to a & b. Guido's time machine strike

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

2017-11-29 Thread Steve Barnes
On 28/11/2017 23:15, Alon Snir wrote: > On Wed, Nov 29, 2017 at 5:46 AM, Alon Snir wrote: >> I would like to mention that the issue of assignment to a target list, is >> also relevant to the case of elementwise assignment to a mutable sequence >> (e.g. lists and arrays). Here as well, the rhs

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

2017-11-29 Thread Greg Ewing
Brendan Barnwell wrote: That's an interesting analysis, but I don't think your view is really the right one. It *is* unpacking a suitcase, it's just that *if necessary* the suitcase is constructed just in time for you to unpack it. I don't think that's right. An iterator created from a seque

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

2017-11-29 Thread Brendan Barnwell
On 2017-11-29 20:43, Steven D'Aprano wrote: At the point that you are conjuring from thin air an invisible suitcase that is an exact clone of the original suitcase, in order to unpack the clone without disturbing the original, I think the metaphor is so far from the real-world unpacking of suitca

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

2017-11-29 Thread Steven D'Aprano
On Wed, Nov 29, 2017 at 03:08:43PM -0800, Brendan Barnwell wrote: > On 2017-11-29 14:21, Greg Ewing wrote: > >On the other hand, some people seem to be interpreting > >the word "unpack" as in "unpack a suitcase", i.e. the > >suitcase is empty afterwards. But unpacking has never > >meant that in Py

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

2017-11-29 Thread Steven D'Aprano
On Thu, Nov 30, 2017 at 11:21:48AM +1300, Greg Ewing wrote: > It seems that many people think about unpacking rather > differently from the way I do. I think the difference > is procedural vs. declarative. > > To my way of thinking, something like > >a, b, c = x > > is a pattern-matching op

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

2017-11-29 Thread Steven D'Aprano
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 w

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

2017-11-29 Thread Brendan Barnwell
On 2017-11-29 14:21, Greg Ewing wrote: C Anthony Risinger wrote: `a, b, ...` to me says "pull out a and b and throw away the rest"... > The mere presence of more characters (...) implies something else will *happen* to the remaining items, not that they will be skipped. It seems that many

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

2017-11-29 Thread Greg Ewing
C Anthony Risinger wrote: `a, b, ...` to me says "pull out a and b and throw away the rest"... > The mere presence of more characters (...) implies something else will *happen* to the remaining items, not that they will be skipped. It seems that many people think about unpacking rather diffe

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

2017-11-29 Thread Greg Ewing
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. I'm not sure how to explain

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

2017-11-29 Thread C Anthony Risinger
On Mon, Nov 27, 2017 at 3:49 PM, Greg Ewing wrote: > C Anthony Risinger wrote: > >> * Perhaps existence of `__len__` should influence unpacking? There is a >> semantic difference (and typically a visual one too) between 1-to-1 >> matching a fixed-width sequence/container on the RHS to identifiers

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

2017-11-29 Thread Rhodri James
On 28/11/17 23:15, Alon Snir wrote: On Wed, Nov 29, 2017 at 5:46 AM, Alon Snir wrote: I would like to mention that the issue of assignment to a target list, is also relevant to the case of elementwise assignment to a mutable sequence (e.g. lists and arrays). Here as well, the rhs of the assig

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

2017-11-29 Thread Alon Snir
On Wed, Nov 29, 2017 at 5:46 AM, Alon Snir wrote: > I would like to mention that the issue of assignment to a target list, is > also relevant to the case of elementwise assignment to a mutable sequence > (e.g. lists and arrays). Here as well, the rhs of the assignment statement > states the num

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

2017-11-28 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 06:46:18PM +, Alon Snir wrote: > I would like to mention that the issue of assignment to a target list, > is also relevant to the case of elementwise assignment to a mutable > sequence (e.g. lists and arrays). Here as well, the rhs of the > assignment statement state

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

2017-11-28 Thread Kirill Balunov
2017-11-28 22:50 GMT+03:00 Guido van Rossum : > On Tue, Nov 28, 2017 at 11:44 AM, Kirill Balunov > wrote: > >> Although I have never used Python 2, the idea to distinguish fixed-sized >> and something lazy, even for Python 4, reminds me of the transition from >> str-unicode to the present state o

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

2017-11-28 Thread Guido van Rossum
On Tue, Nov 28, 2017 at 11:44 AM, Kirill Balunov wrote: > Although I have never used Python 2, the idea to distinguish fixed-sized > and something lazy, even for Python 4, reminds me of the transition from > str-unicode to the present state of affairs, but with much higher impact.To > be honest,

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

2017-11-28 Thread Rhodri James
On 28/11/17 18:46, Alon Snir wrote: I would like to mention that the issue of assignment to a target list, is also relevant to the case of elementwise assignment to a mutable sequence (e.g. lists and arrays). Here as well, the rhs of the assignment statement states the number of elements to be

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

2017-11-28 Thread Kirill Balunov
2017-11-28 10:06 GMT+03:00 C Anthony Risinger : > > If not already considered, what if the RHS had to be explicitly unpacked? > > Something like: > > a, b, c = *iterator > > Which would essentially be: > > a, b, c = (*iterator,) > > This enables lazy assignment by default but `*` can force complet

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

2017-11-28 Thread Chris Angelico
On Wed, Nov 29, 2017 at 5:46 AM, Alon Snir wrote: > I would like to mention that the issue of assignment to a target list, is > also relevant to the case of elementwise assignment to a mutable sequence > (e.g. lists and arrays). Here as well, the rhs of the assignment statement > states the num

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

2017-11-28 Thread Alon Snir
I would like to mention that the issue of assignment to a target list, is also relevant to the case of elementwise assignment to a mutable sequence (e.g. lists and arrays). Here as well, the rhs of the assignment statement states the number of elements to be assigned. Consequently, the following

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

2017-11-27 Thread Kirill Balunov
2017-11-28 0:52 GMT+03:00 Chris Angelico : > On Tue, Nov 28, 2017 at 8:49 AM, Guido van Rossum > wrote: > > My PEP queue for Python 3.7 is full though, so I would like to put this > off > > until 3.8. > > > > Yeah, I don't think this could reasonably be raced into 3.7 even if it > were critically

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

2017-11-27 Thread C Anthony Risinger
On Nov 28, 2017 12:32 AM, "Steven D'Aprano" wrote: 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 nee

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

2017-11-27 Thread Steven D'Aprano
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

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

2017-11-27 Thread electronnn
How about x, y ?= iterable with ?= being the lazy assignment operator? On Tue, Nov 28, 2017 at 9:45 AM, Steven D'Aprano wrote: > On Mon, Nov 27, 2017 at 06:31:28PM -0800, Mike Miller wrote: > > > Believe the question behind the idea was, how to grab a couple items and > > then *stop?* If the sy

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

2017-11-27 Thread Steve Barnes
On 27/11/2017 21:49, Guido van Rossum wrote: > On Mon, Nov 27, 2017 at 1:32 PM, Chris Angelico > wrote: > > On Tue, Nov 28, 2017 at 8:24 AM, Guido van Rossum > wrote: > > On Mon, Nov 27, 2017 at 1:18 PM, Greg Ewing > mailto:greg.ew

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

2017-11-27 Thread Steven D'Aprano
On Mon, Nov 27, 2017 at 06:31:28PM -0800, Mike Miller wrote: > Believe the question behind the idea was, how to grab a couple items and > then *stop?* If the syntax route is chosen, I'd expect something that > tells me it is going to stop, like a "full stop" as the period/dot is > called in jo

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

2017-11-27 Thread Greg Ewing
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. -- Greg ___ Python-ideas mailing list Python-idea

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

2017-11-27 Thread Greg Ewing
Kirill Balunov wrote: So someone too perlish clever can assume that with the proposed syntax: >>> def gen(): >>> for i in ['a', 'b', 'c', 'd']: >>> v = x if 'x' in globals() else 'var ' >>> yield v + i >>> x, y = gen() >>> x var a >>> y var ab There's no need for t

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

2017-11-27 Thread Mike Miller
Hmm, I didn't like the options below because they say to me, "consume everything:" x, y, * = iterable x, y, ... = iterable Believe the question behind the idea was, how to grab a couple items and then *stop?* If the syntax route is chosen, I'd expect something that tells me it is go

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

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 11:15:56AM +1300, Greg Ewing wrote: > Guido van Rossum wrote: > >While it appears to rhyme with the use of a lone > >'*' in function signatures, it would actually mean the opposite: in > >signatures it means "don't allow any more". > > That's the usage that's out of step

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

2017-11-27 Thread Steven D'Aprano
On Mon, Nov 27, 2017 at 06:53:23PM +0200, Koos Zevenhoven wrote: > Making iterators behave like sequences (slicing etc.) introduces various > issues including memory considerations and backwards compatibility. Perhaps. I'm not going to actively champion the idea of supporting slicing for iterat

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

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 10:49:45AM +1300, Greg Ewing wrote: > C Anthony Risinger wrote: > >* Perhaps existence of `__len__` should influence unpacking? There is a > >semantic difference (and typically a visual one too) between 1-to-1 > >matching a fixed-width sequence/container on the RHS to iden

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

2017-11-27 Thread Greg Ewing
Guido van Rossum wrote: Is this problem really important enough that it requires dedicated syntax? Isn't the itertools-based solution good enough? Well, it works, but it feels very clumsy. It's annoying to have to specify the number of items in two places. Also, it seems perverse to have to te

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

2017-11-27 Thread Serhiy Storchaka
27.11.17 23:24, Guido van Rossum пише: Is this problem really important enough that it requires dedicated syntax? Isn't the itertools-based solution good enough? (Or failing that, couldn't we add something to itertools to make it more readable rather than going straight to new syntax?) I want

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

2017-11-27 Thread Paul Moore
On 27 November 2017 at 21:54, Kirill Balunov wrote: > 2017-11-27 19:23 GMT+03:00 Paul Moore : > >> >> It should be reasonably easy >> to do a code search for something like "=.*islice", to find code >> that's a candidate for using the proposed syntax. I suspect there's >> very little code like tha

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

2017-11-27 Thread Greg Ewing
Guido van Rossum wrote: While it appears to rhyme with the use of a lone '*' in function signatures, it would actually mean the opposite: in signatures it means "don't allow any more". That's the usage that's out of step with the rest -- all the others can be seen as some form of wildcard. So

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

2017-11-27 Thread Kirill Balunov
2017-11-27 19:23 GMT+03:00 Paul Moore : > It should be reasonably easy > to do a code search for something like "=.*islice", to find code > that's a candidate for using the proposed syntax. I suspect there's > very little code like that. While isclice is something equivalent, it can be used in

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 8:49 AM, Guido van Rossum wrote: > My PEP queue for Python 3.7 is full though, so I would like to put this off > until 3.8. > Yeah, I don't think this could reasonably be raced into 3.7 even if it were critically important, and it's not. 3.8 will be fine. Kirill, do you w

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

2017-11-27 Thread Guido van Rossum
On Mon, Nov 27, 2017 at 1:32 PM, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 8:24 AM, Guido van Rossum > wrote: > > On Mon, Nov 27, 2017 at 1:18 PM, Greg Ewing > > > wrote: > >> > >> Chris Angelico wrote: > >>> > >>> The problem is that it depends on internal whitespace to > >>> distinguish

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

2017-11-27 Thread Greg Ewing
C Anthony Risinger wrote: * Perhaps existence of `__len__` should influence unpacking? There is a semantic difference (and typically a visual one too) between 1-to-1 matching a fixed-width sequence/container on the RHS to identifiers on the LHS, even if they look similar (ie. "if RHS has a leng

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

2017-11-27 Thread Kirill Balunov
While I was more optimistic when I proposed this idea, moving on I gradually become less and less optimistic. I did not underestimate how much this would change the semantics. At present, if the lhs is comma-separated list of targets, the rhs is evaluated, and only then if they match the assignment

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 8:24 AM, Guido van Rossum wrote: > On Mon, Nov 27, 2017 at 1:18 PM, Greg Ewing > wrote: >> >> Chris Angelico wrote: >>> >>> The problem is that it depends on internal whitespace to >>> distinguish it from augmented assignment; >> >> >> Ah, didn't spot that. I guess the ell

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

2017-11-27 Thread Guido van Rossum
On Mon, Nov 27, 2017 at 1:18 PM, Greg Ewing wrote: > Chris Angelico wrote: > >> The problem is that it depends on internal whitespace to >> distinguish it from augmented assignment; >> > > Ah, didn't spot that. I guess the ellipsis is the next best > thing then. > > An alternative would be to req

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

2017-11-27 Thread Guido van Rossum
On Mon, Nov 27, 2017 at 1:13 PM, Greg Ewing wrote: > Chris Angelico wrote: > > x, y, * = iter # unpack into nothing >> > > I'm surprised this isn't already allowed. It seems like the > One Obvious Way to me. I'm not that surprised. While it appears to rhyme with the use of a lone '*' in functio

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

2017-11-27 Thread Greg Ewing
Chris Angelico wrote: The problem is that it depends on internal whitespace to distinguish it from augmented assignment; Ah, didn't spot that. I guess the ellipsis is the next best thing then. An alternative would be to require parens: (x, y, *) = z -- Greg ___

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

2017-11-27 Thread Greg Ewing
Chris Angelico wrote: x, y, * = iter # unpack into nothing I'm surprised this isn't already allowed. It seems like the One Obvious Way to me. -- Greg ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/pyth

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

2017-11-27 Thread C Anthony Risinger
This proposal resonates with me. I've definitely wanted to use unpacking to crank an iterator a couple times and move on without exhausting the iterator. It's a very natural and intuitive meaning for unpacking as it relates to iterators. In my mind, this ask is aligned with, and has similar motiva

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

2017-11-27 Thread Koos Zevenhoven
On Mon, Nov 27, 2017 at 3:55 PM, Steven D'Aprano wrote: > On Mon, Nov 27, 2017 at 12:17:31PM +0300, Kirill Balunov wrote: > ​​ > > > 2. Should this work only for generators or for any iterators? > > I don't understand why you are even considering singling out *only* > generators. A generator is a

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

2017-11-27 Thread Paul Moore
On 27 November 2017 at 16:05, Chris Angelico wrote: > On Tue, Nov 28, 2017 at 2:35 AM, Steven D'Aprano wrote: >> In this case, there is a small but real benefit to counting the >> assignment targets and being explicit about the number of items to >> slice. Consider an extension to this "non-consu

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 2:35 AM, Steven D'Aprano wrote: > In this case, there is a small but real benefit to counting the > assignment targets and being explicit about the number of items to > slice. Consider an extension to this "non-consuming" unpacking that > allowed syntax like this to pass si

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 1:46 AM, Steven D'Aprano wrote: > On Tue, Nov 28, 2017 at 01:01:01AM +1100, Chris Angelico wrote: > >> And the status quo is noisy and has duplicated >> information (you have to match the ", 2" to the number of assignment >> targets). > > Er, not really. How about: > > a, b

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

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 01:14:40AM +1100, Chris Angelico wrote: > Nah, far easier: > > x, y = iter(it) > > since that'll be a no-op in the first case Not necessarily a no-op. __iter__ might have side-effects. Of course if you can guarantee that you ONLY have iterators, then there's no need to

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

2017-11-27 Thread Koos Zevenhoven
On Mon, Nov 27, 2017 at 4:50 PM, Kirill Balunov wrote: > > I really do not like to use "starred" targets in any way: > > x, y, * = iterable > ​This one won't work, because it looks like in-place multiplication (__imul__) which clashes with the above for a single name as assignment target: x *=

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

2017-11-27 Thread Kirill Balunov
2017-11-27 17:14 GMT+03:00 Chris Angelico : > > > Nah, far easier: > > x, y = iter(it) > Yes, you are right. >> 2. Readable and not so verbose code > >> 3. Optimized case for x,y,*z = iterator > > > > The semantics of that are already set: the first two items are assigned > > to x and y,

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

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 01:01:01AM +1100, Chris Angelico wrote: > And the status quo is noisy and has duplicated > information (you have to match the ", 2" to the number of assignment > targets). Er, not really. How about: a, b = islice(iterable, 3, 10, 4) A somewhat unusual case, to be sure, b

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

2017-11-27 Thread Kirill Balunov
> > > To show this on simple example: > > > > >>> from itertools import count, islice > > >>> it = count() > > >>> x, y = it > > >>> it > > count(3) > > For everyone else who was confused by this, as I was, that's not > actually a copy and paste from the REPL. There should be a ValueError > raised

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 12:55 AM, Steven D'Aprano wrote: > But even if we decide on a simple rule like "iterator unpacking depends > on the number of targets, all other iterables don't", I think that will > be a bug magnet. It will mean that you can't rely on this special > behaviour unless you s

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

2017-11-27 Thread Steven D'Aprano
On Mon, Nov 27, 2017 at 03:31:38PM +0300, Kirill Balunov wrote: > As I can see at the moment, these cases should behave differently: > > >>> x, y = [1,2,3,4] # must raise ValueError > >>> x, y = iter([1,2,3,4]) # should work I *completely disagree* that they should behave differ

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

2017-11-27 Thread Chris Angelico
On Tue, Nov 28, 2017 at 12:44 AM, Daniel Moisset wrote: > On 27 November 2017 at 06:40, Chris Angelico wrote: >> >> Here are a few syntaxes that I believe have been proposed at various >> times: >> >> x, y = islice(iter, 2) # status quo >> x, y = iter # your proposal >> x, y, = iter # omit last d

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

2017-11-27 Thread Steven D'Aprano
On Mon, Nov 27, 2017 at 12:17:31PM +0300, Kirill Balunov wrote: > Currently during assignment, when target list is a comma-separated list of > targets (*without "starred" target*) the rule is that the object (rhs) must > be an iterable with the same number of items as there are targets in the > tar

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

2017-11-27 Thread Daniel Moisset
On 27 November 2017 at 06:40, Chris Angelico wrote: > Here are a few syntaxes that I believe have been proposed at various > times: > > x, y = islice(iter, 2) # status quo > x, y = iter # your proposal > x, y, = iter # omit last destination > Just to clear the list, this one (trailing comma) wou

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

2017-11-27 Thread Chris Angelico
On Mon, Nov 27, 2017 at 11:31 PM, Kirill Balunov wrote: > >> In terms of language proposals, you can't just say "don't need values >> for"; the semantics have to be EITHER "consume and discard" OR "don't >> consume". We already have a perfectly good way of spelling "consume >> and discard": >> >>

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

2017-11-27 Thread Kirill Balunov
2017-11-27 15:39 GMT+03:00 Paul Moore : > On 27 November 2017 at 12:31, Kirill Balunov > wrote: > > As I can see at the moment, these cases should behave differently: > > > x, y = [1,2,3,4] # must raise ValueError > x, y = iter([1,2,3,4]) # should work > > > > But at th

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

2017-11-27 Thread Paul Moore
On 27 November 2017 at 12:31, Kirill Balunov wrote: > As I can see at the moment, these cases should behave differently: > x, y = [1,2,3,4] # must raise ValueError x, y = iter([1,2,3,4]) # should work > > But at the same time, it violates current situation. So maybe, as

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

2017-11-27 Thread Kirill Balunov
> In terms of language proposals, you can't just say "don't need values > for"; the semantics have to be EITHER "consume and discard" OR "don't > consume". We already have a perfectly good way of spelling "consume > and discard": > > x, y, _ = iter > You mean ( x, y, *_ = iter ) ? Since this has

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

2017-11-27 Thread Chris Angelico
On Mon, Nov 27, 2017 at 9:45 PM, Kirill Balunov wrote: > 2017-11-27 12:40 GMT+03:00 Chris Angelico : >> If you use "x, y, *z = gen1()", you'll trigger all the prints and >> completely consume the generator. With gen2(), you'll get an infinite >> loop. Both of those are semantically different from

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

2017-11-27 Thread Kirill Balunov
2017-11-27 12:40 GMT+03:00 Chris Angelico : > On Mon, Nov 27, 2017 at 8:17 PM, Kirill Balunov > wrote: > > In many cases it is possible to do this right now, but in too verbose > way: > > > x, y = islice(gen(), 2) > > > > But it seems for me that: > > > x, y = gen() > > > > Looks the sa

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

2017-11-27 Thread Chris Angelico
On Mon, Nov 27, 2017 at 8:17 PM, Kirill Balunov wrote: > In many cases it is possible to do this right now, but in too verbose way: > x, y = islice(gen(), 2) > > But it seems for me that: > x, y = gen() > > Looks the same, easy to follow and not so verbose. This, AIUI, is the nub of the

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

2017-11-27 Thread Kirill Balunov
Currently during assignment, when target list is a comma-separated list of targets (*without "starred" target*) the rule is that the object (rhs) must be an iterable with the same number of items as there are targets in the target list. That is, no check is performed on the number of targets presen