[issue3692] improper scope in list comprehension, when used in class declaration

2018-08-27 Thread Mark Dickinson
Change by Mark Dickinson : -- nosy: +mark.dickinson ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue3692] improper scope in list comprehension, when used in class declaration

2018-07-10 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Indeed, this issue is more complex than it looked to me. Technically, LOAD_FAST, which is used for reading the loop control variables in comprehensions, uses the array f->f_localsplus, while LOAD_NAME uses f->f_locals and f->f_globals. When executing class

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-07 Thread Guido van Rossum
Guido van Rossum added the comment: > I don't think this will need drastic changes. IIRC LOAD_NAME loads from the *local* scope, which will be the synthetic function created for the comprehension (whose scope contains the loop control variables). We may need a new opcode

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I don't think this will need drastic changes. Just setting some flags here or there for making comprehensions using LOAD_NAME instead of LOAD_GLOBAL. The fix should lie near the fix for issue33346. --

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-07 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: > Bug or not this is not going to change without a PEP, so I'm not sure it's a > good idea to keep this issue open. I agree this requires a PEP. I would like to keep this open as a place for pre-PEP discussions among those interested

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-03 Thread Guido van Rossum
Guido van Rossum added the comment: There's a proposal for a fix currently in PEP 572. I'm linking to the commit here because we're likely to remove it from PEP 572, but it may be proposed as a separate PEP:

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-03 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: See https://bugs.python.org/issue33346 for yet another example where implicit function scope complicates life. -- ___ Python tracker

[issue3692] improper scope in list comprehension, when used in class declaration

2018-05-03 Thread Ivan Levkivskyi
Ivan Levkivskyi added the comment: Mariatta, > While I understand why it behaves the way it is now, but it seems wrong > behavior. Perhaps we should look into finding a solution. I am all in favour of dropping implicit function scope in comprehensions (mostly because

[issue3692] improper scope in list comprehension, when used in class declaration

2018-04-25 Thread Mariatta Wijaya
Mariatta Wijaya added the comment: I'm re-opening this, since the behavior sounds like a bug to me. While I understand why it behaves the way it is now, but it seems wrong behavior. Perhaps we should look into finding a solution. -- nosy: +Mariatta

[issue3692] improper scope in list comprehension, when used in class declaration

2018-03-17 Thread Simon Charette
Simon Charette added the comment: I stumble upon this bug when porting a Python 2 codebase to 3 and suddenly got a NameError for the following code. class Foo: a = [1,2,3] b = [4,5,6] c = [x * y for x in a for y in b] NameError: name 'b'

[issue3692] improper scope in list comprehension, when used in class declaration

2013-07-05 Thread John McDonald
John McDonald added the comment: Could we possibly revisit this? This feels like an implementation detail, not something specified. Consider the different cases: Type help, copyright, credits or license for more information. class A: ... b = 5 ... print(locals()) ... x = [i*i for i in

[issue3692] improper scope in list comprehension, when used in class declaration

2008-08-27 Thread Georg Brandl
Georg Brandl [EMAIL PROTECTED] added the comment: This won't change -- in 3.0, list comprehensions and generator expressions are both implemented using a function, so it's like the following: class Foo: attribute1 = 1 def f(): return attribute1 attribute2 = f() --

[issue3692] improper scope in list comprehension, when used in class declaration

2008-08-26 Thread kai zhu
New submission from kai zhu [EMAIL PROTECTED]: in 3rd line, list comprehension tries to access class_attribute1 as a global variable (code is valid in python 2.5) class Foo(object): ... class_attribute1 = 1 ... class_attribute2 = [class_attribute1 for x in range(8)] ... Traceback (most

[issue3692] improper scope in list comprehension, when used in class declaration

2008-08-26 Thread Daniel Diniz
Daniel Diniz [EMAIL PROTECTED] added the comment: I believe the problem is that list comprehensions in 3.0 have scope like that of genexprs in 2.5, but the change was deliberate (as it also avoids leaking of temp variables). Compare to 2.5: class Foo(object): ...class_attribute1 = 1 ...