On Mon, Jun 25, 2018 at 5:14 PM Steve Holden <steve@holdenweb.com> wrote:
I'd like to ask: how many readers of ​
​this email have ever deliberately taken advantage of the limited Python 3 scope in comprehensions and generator expressions to use what would otherwise be a conflicting local variable name?​

I have never once *deliberately* utilized the Python 3 local scoping in comprehensions.  There were a few times in Python 2 where I made an error of overwriting a surrounding name by using it in a comprehension, and probably Python 3 has saved me from that a handful of times.

Where I ever made such an error, it was with names like 'x' and 'i' and 'n'.  They are useful for quick use, but "more important" variables always get more distinctive names anyway.  Had the Python 2 behavior remained, I would have been very little inconvenienced; and I suppose comprehensions would have been slightly less "magic" (but less functional-programming).

I appreciate that the scope limitation can sidestep accidental naming errors, which is a good thing.

Unfortunately, unless we anticipate Python 4 (or whatever) also making for loops have an implicit scope, I am left wondering whether it's not too large a price to pay. After all, special cases aren't special enough to break the rules, and unless the language is headed towards implicit scope for all uses of "for" one could argue that the scope limitation is a special case too far. It certainly threatens to be yet another confusion for learners, and while that isn't the only consideration, it should be given due weight.
Python-Dev mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-dev/mertz%40gnosis.cx

Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.