This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Inyeol.Lee, Jim Fasarakis-Hilliard, arigo, belopolsky, benjamin.peterson, danielsh, emptysquare, erickt, esc24, georg.brandl, glyph, gvanrossum, levkivskyi, ncoghlan, rhettinger, serhiy.storchaka
Date 2017-11-23.11:38:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Sure, you can technically do that, but you'll have to rewrite most of the symtable pass in the compiler, since you won't be able to re-use the current recursive descent algorithms (which are designed to handle function scopes). That ran afoul of "If the implementation is hard to explain, it's a bad idea."

Where that gets particularly nasty is when you nest comprehensions with the *same* iteration variable name:

    >>> [[i for i in range(2)] for i in range(2)]
    [[0, 1], [0, 1]]

Now your name generator needs to be clever enough to account for how many levels deep it is. You also run into the lexical scoping problem anyway once a lambda expression shows up:

    >>> [[(lambda i=i: i)() for i in range(2)] for i in range(2)]
    [[0, 1], [0, 1]]
    >>> [[(lambda: i)() for i in range(2)] for i in range(2)]
    [[0, 1], [0, 1]]

As noted earlier, not impossible to resolve, but for from the "simple" option that folks seem to believe it is (and which I thought it would be before I actually tried to implement it while respecting Python's lexical scoping rules).
Date User Action Args
2017-11-23 11:38:01ncoghlansetrecipients: + ncoghlan, gvanrossum, arigo, georg.brandl, rhettinger, belopolsky, benjamin.peterson, erickt, glyph, Inyeol.Lee, serhiy.storchaka, esc24, danielsh, emptysquare, levkivskyi, Jim Fasarakis-Hilliard
2017-11-23 11:38:01ncoghlansetmessageid: <>
2017-11-23 11:38:01ncoghlanlinkissue10544 messages
2017-11-23 11:38:01ncoghlancreate