[issue26951] Unintuitive error when using generator expression in class property

2019-07-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See also issue3692. -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mail

[issue26951] Unintuitive error when using generator expression in class property

2016-05-04 Thread Mark Dickinson
Mark Dickinson added the comment: The outer for loop in a generator expression is evaluated immediately; everything after that is evaluated lazily. This was a deliberate design choice: see https://www.python.org/dev/peps/pep-0289/#early-binding-versus-late-binding for some rationale. This expl

[issue26951] Unintuitive error when using generator expression in class property

2016-05-04 Thread Xiang Zhang
Changes by Xiang Zhang : -- nosy: +xiang.zhang ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pyt

[issue26951] Unintuitive error when using generator expression in class property

2016-05-04 Thread Steven D'Aprano
Steven D'Aprano added the comment: On snap! Nicely found! This seems to have something to do with the way generator expressions are run inside their own scope. In Python 2.7, a list comprehension in a class sees the locals correctly: py> class K: ... a = 2; x = [a+i for i in range(a)] ...

[issue26951] Unintuitive error when using generator expression in class property

2016-05-04 Thread Emanuel Barry
Emanuel Barry added the comment: Using a simple metaclass shows that definition order is not at fault here: >>> class PrintOrder(dict): ... def __setitem__(self, item, value): ... print(item, value) ... super().__setitem__(item, value) ... >>> class Show(type): ... def __prepare__(na

[issue26951] Unintuitive error when using generator expression in class property

2016-05-04 Thread Corey Farwell
New submission from Corey Farwell: ``` class A: B = range(10) C = frozenset([4, 5, 6]) D = list(i for i in B) E = list(i for i in B if i in C) ``` ``` coreyf@frewbook-pro /tmp [1]> python3 a.py Traceback (most recent call last): File "a.py", line 1, in class A: File "a.