[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-10 Thread Jan Christoph
Jan Christoph added the comment: Updated example with reversed variable order for reference. This really seems to be related to issue3692, but really not the same thing. IMHO both `a` and `b` should be passed in a situation like this: a = range(5) b = range(3) c = [x+y for x in a for y

[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-10 Thread Jan Christoph
Jan Christoph added the comment: Okay, so we're a in another scope inside the dictionary comprehension (all comprehensions for that matter), and only one symbol is passed to the inside. That's why `strange_reversed_working = {x+s.replace('(+/-)',''):None for x in infts.split(', ') for s in

[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-10 Thread Jan Christoph
Jan Christoph added the comment: But the simpler dictionary compprehension `{s.replace('(+/-)',''):None for s in infts.split(', ')}` works perfectly. Shouldn't that also give the error if it was a scope issue? -- ___ Python tracker

[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This looks like a duplicate of issue3692. -- nosy: +serhiy.storchaka resolution: -> duplicate stage: -> resolved status: open -> closed superseder: -> improper scope in list comprehension, when used in class declaration

[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-09 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I think this is explained in the below answers with example that the left most loop in the comprehension has access to the class variables which the nested comprehensions don't have https://stackoverflow.com/a/22692274/2610955

[issue34076] Nested loop in dictionary comprehension gives `global name not defined` inside class

2018-07-09 Thread Jan Christoph
New submission from Jan Christoph : The python code: ``` class _tri(object): infts = '(+/-)inf, (+/-)infty, (+/-)infinity' strange_failing = {x+s.replace('(+/-)',''):None for x in ('+','-','') for s in infts.split(', ')} ``` gives a `global name 'infts' is not defined` exception,