A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2002-November/029878.html below:

[Python-Dev] metaclass insanity

[Python-Dev] metaclass insanityGuido van Rossum guido@python.org
Mon, 04 Nov 2002 15:54:48 -0500
> > What happens for nested classes?
> >
> > In
> >
> > class X:
> >     class Y:
> >         pass
> >
> > are X.Y instances picklable without extra fiddling?
> 
> Picklable functions and classes must be defined in the top level of a 
> module. Nested classes, and instances thereof, cannot be pickled at all.

BTW, I consider this a flaw.

In the case of nested classes, a possible solution might be for
X.Y.__name__ to be "X.Y" rather than plain "Y".  Then a simple change
to pickle (or to getattr :-) could allow the correct unpickling.

This won't work for classes defined inside functions though -- those
are never picklable.  But making them module-global would be a simple
enough fix (also more efficient, since the class definition code is
executed on every function call).

Can someone provide a reason why you'd want to use nested classes?
I've never felt this need myself.  What are the motivations?

--Guido van Rossum (home page: http://www.python.org/~guido/)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4