Why nested scope rules do not apply to inner Class?

Calvin Spealman ironfroggy at gmail.com
Tue Aug 12 23:15:23 CEST 2008

The issue has been brought up several times before. There have been
proposals to make nested classes better supported, but they are always
shut down. The vote is always against it. Your metaclass example is
one thing, but its not really applicable here. I've never seen or
would encourage nested classes even in that case. The metaclass is
typically defined on its own, and then referenced by one or more
classes that use it. 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.

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.


On Tue, Aug 12, 2008 at 4:40 PM, Maric Michaud <maric at aristote.info> wrote:
> Le Tuesday 12 August 2008 15:51:30 Calvin Spealman, vous avez écrit :
>> The simple answer is "Dont nest classes. It is not supported."
> I can't agree with this, there are many common idioms in python which involve
> nested classes, this one is often used :
> class foo(object) :
>    class __metaclass__(type) :
>        ....
> This is *not* an oddity of the language, and the first time I came to the
> genexp problem (see my first post), I really thought it was a bug (i posted
> here some monthes ago about this). This behavior is a bit fancy and hard to
> document and even explain as a design choice.
> I don't know what others (more invovled in python development) think of this,
> but I feel th current situation is not acceptable for the long term, maybe
> making classes scope behave more like function (closures) is a solution.
> --
> _____________
> Maric Michaud

Read my blog! I depend on your acceptance of my opinion! I am interesting!
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

More information about the Python-list mailing list