New submission from Alex Mashianov <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue34517>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com