Why nested scope rules do not apply to inner Class?

Cousson, Benoit b-cousson at ti.com
Tue Aug 12 05:29:18 EDT 2008


Hi,

I'd like to be able to use a nested class (C1) from another sibling nested class (C3). This looks very similar to the nested scopes of functions except that it does not work.

class A(object):
	pass

class B(object):
	
	class C1(object):
		pass

	class C2(C1):
		foo = A

	class C3(object):
		foo = C1

The funny thing is that C2 can inherit from C1 but C3 cannot reference C1. B.C1 does not work either, but in that case it makes sense since B is still being defined. 
Is this a language limitation or something that does not make sense at all?

I'm wondering as well if the new nonlocal statement will fix that in py3k?

Thanks in advance,
Benoit




More information about the Python-list mailing list