[New-bugs-announce] [issue34517] Error referencing local variables in dict comprehensions inside class definitions
Alex Mashianov
report at bugs.python.org
Mon Aug 27 04:42:26 EDT 2018
New submission from Alex Mashianov <mashianov at gmail.com>:
This code:
class A:
a = 1
b = {str(x): x for x in range(5) if x != a}
Produces following error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<input>", line 3, in A
File "<input>", line 3, in <dictcomp>
NameError: name 'a' is not defined
Which i think it shouldn't produce. Issue occurs only in dict comprehensions inside class definitions referencing class attributes(which are in local scope during definition).
----------
components: Interpreter Core
messages: 324156
nosy: Alex Mashianov
priority: normal
severity: normal
status: open
title: Error referencing local variables in dict comprehensions inside class definitions
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34517>
_______________________________________
More information about the New-bugs-announce
mailing list