On 9 May 2018 at 03:57, Tim Peters <tim.pet...@gmail.com> wrote: > These all match my expectations. Some glosses: > > [Guido] > > We should probably define what happens when you write [p := p for p in > > range(10)]. I propose that this overwrites the loop control variable > rather > > than creating a second p in the containing scope -- either way it's > probably > > a typo anyway. > > A compile-time error would be fine by me too. Creating two meanings > for `p` is nuts - pick one in case of conflict. I suggested before > that the first person with a real use case for this silliness should > get the meaning their use case needs, but nobody bit, so "it's local > then" is fine. >
I'd suggest that the handling of conflicting global and nonlocal declarations provides a good precedent here: >>> def f(): ... global x ... nonlocal x ... x = 1 ... File "<stdin>", line 2 SyntaxError: name 'x' is nonlocal and global Since using a name as a binding target *and* as the iteration variable would effectively be declaring it as both local and nonlocal, or as local and global. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/