Issue 30577: Multidimensional comprehensions cannot access class variables except in the first for
Created on 2017-06-05 23:56 by fengyang.wang, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg295220 - (view) | Author: Fengyang Wang (fengyang.wang) | Date: 2017-06-05 23:56 | |
Reduced reproduction:
class X:
r = [1, 2, 3]
z = [(i, j) for i in [4, 5] for j in r]
fails with "NameError: name 'r' is not defined". The expected behavior would be for r to be resolved as the r in the class namespace. Note in contrast that
class Y:
r = [1, 2, 3]
z = [(i, j) for j in r for i in [4, 5]]
does not fail.
(Version 3.5.2 on Windows)
|
|||
| msg295221 - (view) | Author: Fengyang Wang (fengyang.wang) | Date: 2017-06-05 23:57 | |
By the way, in Python 2.7 at least, this was working. |
|||
| msg295223 - (view) | Author: Fengyang Wang (fengyang.wang) | Date: 2017-06-06 00:06 | |
It looks like this is a duplicate of http://bugs.python.org/issue11796 Sorry for the noise. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:47 | admin | set | github: 74762 |
| 2017-06-06 00:13:57 | zach.ware | set | status: open -> closed superseder: Comprehensions in a class definition mostly cannot access class variable stage: resolved |
| 2017-06-06 00:06:17 | fengyang.wang | set | resolution: duplicate messages: + msg295223 |
| 2017-06-05 23:57:48 | fengyang.wang | set | messages: + msg295221 |
| 2017-06-05 23:56:16 | fengyang.wang | create | |