[Python-Dev] Pickling instances of nested classes
pedronis at strakt.com
Wed Mar 30 01:47:16 CEST 2005
Walter Dörwald wrote:
> For XML: 1) Those classes are the element types and the nested classes
> are the attributes. 2) Being able to define those attributes as separate
> classes makes it possible to implement custom functionality (e.g. for
> validation or for handling certain attribute types like URLs, colors etc.)
> and 3) Those classes get instantiated when an XML tree is created or parsed.
> A framework that does this (and my main motivation for writing this :)) is
> XIST (see http://www.livinglogic.de/Python/xist/).
> For the ORM case: Each top level class defines a table and the nested
> classes are the fields, i.e. something like this:
> class person(Table):
> class firstname(Varchar):
> "The person's first name"
> null = False
> class lastname(Varchar):
> "The person's last name"
> null = False
> class password(Varchar):
> "Login password"
> def validate(self, value):
> if not any(c.islower() for c in value) and \
> not any(c.isupper() for c in value) and \
> not any(c.isdigit() for c in value):
> raise InvalidField("password requires a mix of upper and lower"
> "case letters and digits")
> Instances of these classes are the records read from the database. A framework
> that does something similar to this (although AFAIK fields are not nested
> classes is SQLObject (http://sqlobject.org/)
> So is this change wanted? useful? implementable with reasonable effort? Or
> just not worth it?
notice that in this cases often metaclasses are involved or could easely
be, so if pickling would honor __reduce__ or __reduce_ex__ on
metaclasses (which right now it doesn't treating their instances as
normal classes) one could roll her own solution without the burden for
the language of implementing pickling of nested classes in general, so I
think that would make more sense, to add support to honor
__reduce__/__reduce_ex__ for metaclasses.
More information about the Python-Dev