Hm, so maybe we shouldn't touch lambda, but we can at least fix the scope issues for comprehensions and genexprs.

There may still be breakage, when the code defines a global x that is overridden by a class-level x, and a class-level comprehension references x assuming it to be the global. So we need to tread carefully even here -- but this case is weird already:

x = 42
class C:
    x = [1, 2, 3]
    z = [x+y for y in x]  # [43, 44, 45]

Wow!
I had to try it myself!

If I had came across something like the following in a code review :
x = [1, 2]
class C:
    x = [3, 4, 5]
    z = [x for _ in x]

I would have expected C.z to equal either `[[1, 2], [1, 2]]` or `[[3, 4, 5], [3, 4, 5], [3, 4, 5]]`, but surely not `[[1, 2], [1, 2], [1, 2]]`!

Is that intentional, or the result of other way-more-logical decisions?

- Brice
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to