[issue1863] NameError with genexp in class scope

2008-01-18 Thread Georg Brandl

Georg Brandl added the comment:

Amaury Forgeot d'Arc schrieb:

 Well, I'm not sure that the genexpr can be considered as a method, but
 it is certainly a nested code block.

Technically it is a method, that's why this happens. I added a note to the
docs in r60051; closing this as won't fix.

--
nosy: +georg.brandl
resolution:  - wont fix
status: open - closed

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-18 Thread Facundo Batista

Facundo Batista added the comment:

Yes, something was bad with my test. Now I have the same behaviour.

Sorry for the noise.

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-18 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc added the comment:

Facundo, are your sure that your output starts from a fresh environment?
I get:

C:\Python25python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type help, copyright, credits or license for more information.
 class C:
... a = 42
... list(a for _ in 'x')
...
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 3, in C
  File stdin, line 3, in genexpr
NameError: global name 'a' is not defined

This error is actually approximately documented in an obscure sentence
in http://docs.python.org/dev/reference/executionmodel.html#naming


The scope of names defined in a class block is limited to the class
block; it does not extend to the code blocks of methods.


Well, I'm not sure that the genexpr can be considered as a method, but
it is certainly a nested code block.

--
nosy: +amaury.forgeotdarc

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-18 Thread Facundo Batista

Facundo Batista added the comment:

Don't follow you:

 class C:
a = 42
list(a for _ in 'x')

 

Works here! (Python 2.5.1 on win32)

--
nosy: +facundobatista

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-17 Thread Willard

New submission from Willard:

The following code does not work like expected, it triggers a NameError.

class C:
a = 42
list(a for _ in 'x')

 NameError: global name 'a' is not defined 

This issue was discussed on comp.lang.python in the thread Is this a
bug, or is it me?.

--
components: Interpreter Core
messages: 60060
nosy: cptnwillard
severity: minor
status: open
title: NameError with genexp in class scope
type: behavior
versions: Python 2.5

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-17 Thread Raymond Hettinger

Raymond Hettinger added the comment:

I don't follow what you mean.  Can you post a working version of the
code fragment?

--
nosy: +rhettinger

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1863] NameError with genexp in class scope

2008-01-17 Thread Guido van Rossum

Guido van Rossum added the comment:

It's a weakness, not a bug.

Just use a different variable name besides 'a'.

--
nosy: +gvanrossum

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue1863
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com