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.
Created on 2019年07月19日 15:28 by Ákos Tompos, last changed 2022年04月11日 14:59 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg348181 - (view) | Author: Ákos Tompos (Ákos Tompos) | Date: 2019年07月19日 15:28 | |
The following code does work on python 2.7 but fails on python 3.7. The code seems correct. class A: class B: def __init__(self, param): self.param = param l = [B(i) for i in range(10)] The result on: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] Traceback (most recent call last): File "test.py", line 6, in <module> class A: File "test.py", line 11, in A l = [B(i) for i in range(10)] File "test.py", line 11, in <listcomp> l = [B(i) for i in range(10)] NameError: name 'B' is not defined B can be accessed if not inside a generator expression |
|||
| msg348184 - (view) | Author: Karthikeyan Singaravelan (xtreak) * (Python committer) | Date: 2019年07月19日 16:52 | |
I think it's about a class being defined inside another class and not about subclass. This seems to be similar to https://bugs.python.org/issue3692 that discusses about class attribute scope for comprehension. |
|||
| msg348190 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2019年07月19日 18:37 | |
This is a duplicate of issue3692. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:18 | admin | set | github: 81813 |
| 2019年07月19日 18:37:02 | serhiy.storchaka | set | status: open -> closed superseder: improper scope in list comprehension, when used in class declaration nosy: + serhiy.storchaka messages: + msg348190 resolution: duplicate stage: resolved |
| 2019年07月19日 16:52:59 | xtreak | set | nosy:
+ xtreak messages: + msg348184 |
| 2019年07月19日 15:28:48 | Ákos Tompos | create | |