Re: Nested class doesn't see class scope

2016-07-05 Thread eryk sun
On Tue, Jul 5, 2016 at 5:40 AM, Steven D'Aprano wrote: > On Tuesday 05 July 2016 14:41, Ian Kelly wrote: > >> Class definitions don't create closures like functions do. When Python >> executes a class definition, the metaclass creates a dict, and then >> the interpreter execs the class body using

Re: Nested class doesn't see class scope

2016-07-04 Thread Steven D'Aprano
On Tuesday 05 July 2016 14:41, Ian Kelly wrote: > Class definitions don't create closures like functions do. When Python > executes a class definition, the metaclass creates a dict, and then > the interpreter execs the class body using that dict as the locals. > The body of class A has one locals

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 10:41 PM, Ian Kelly wrote: > On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: >> I got this in Python 3.6: >> >> >> py> class A: >> ... var = 999 >> ... print(var) # succeeds >> ... class B: >> ... x = var >> ... >> 999 >> Traceback (most recent c

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:20 PM, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "", line 3, in A >

Re: Nested class doesn't see class scope

2016-07-04 Thread Ian Kelly
On Mon, Jul 4, 2016 at 9:42 PM, Paul Rubin wrote: > Steven D'Aprano writes: >> ... class B: >> ... x = var > > x = A.var Nope. A doesn't exist yet at this point. -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested class doesn't see class scope

2016-07-04 Thread Paul Rubin
Steven D'Aprano writes: > ... class B: > ... x = var x = A.var -- https://mail.python.org/mailman/listinfo/python-list

Re: Nested class doesn't see class scope

2016-07-04 Thread Rustom Mody
On Tuesday, July 5, 2016 at 8:50:57 AM UTC+5:30, Steven D'Aprano wrote: > I got this in Python 3.6: > > > py> class A: > ... var = 999 > ... print(var) # succeeds > ... class B: > ... x = var > ... > 999 > Traceback (most recent call last): > File "", line 1, in > File "

Nested class doesn't see class scope

2016-07-04 Thread Steven D'Aprano
I got this in Python 3.6: py> class A: ... var = 999 ... print(var) # succeeds ... class B: ... x = var ... 999 Traceback (most recent call last): File "", line 1, in File "", line 3, in A File "", line 4, in B NameError: name 'var' is not defined I expected that `va