Why nested scope rules do not apply to inner Class?

Cousson, Benoit b-cousson at ti.com
Wed Aug 13 11:32:00 EDT 2008


> Defining it as a nested class saves you one line
> of code, but IMHO makes the result just a bit more cluttered, while
> reducing the elegance of reusing the metaclass.

The whole point of nested class is to avoid polluting the namespace with classes that are only used locally. So the argument about the elegance of reusing is not very valid in that case.

I agree that they are other ways using module to avoid namespace pollution, but in some case it is easier to use nested class instead and keep everything in the same file.

In my case, I'm trying to use a similar approach as XIST's one, meaning using Python class to model hierarchical data. So clearly nested class is a very nice and easy understandable way to do that.  


> Here are only a few examples of threads giving good reasons against
> class nesting. I've never seen any good arguments for it. There are
> dozens of good reasons we don't encourage it and won't actively
> support it.
> 
> http://mail.python.org/pipermail/python-dev/2005-March/052454.html
> http://mail.python.org/pipermail/python-dev/2002-November/029872.html


>From what I quickly read in these email threads, except for the pickling issue and the fact that Guido does not like nested classes, I do not see strong argument against it either. 

Regards,
Benoit




More information about the Python-list mailing list