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 Ákos Tompos
Recipients Ákos Tompos
Date 2019-07-19.15:28:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1563550128.64.0.536864236908.issue37632@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-07-19 15:28:48Ákos Tompossetrecipients: + Ákos Tompos
2019-07-19 15:28:48Ákos Tompossetmessageid: <1563550128.64.0.536864236908.issue37632@roundup.psfhosted.org>
2019-07-19 15:28:48Ákos Tomposlinkissue37632 messages
2019-07-19 15:28:48Ákos Tomposcreate