[ZODB-Dev] ZODB and new style classes?

Jeremy Hylton jeremy@zope.com
Wed, 26 Jun 2002 12:04:56 -0400


> I've realized that it would be good for me to sub class
> string....

I'm not so sure.
 
> What version of ZODB do I need to do that? I'm using
> StandaloneZODB 1.0 today, but I got the impression that
> this version doesn't handle Python 2.2 new style classes.
> (TypeError: metatype conflict among bases)

I expect you'll get a metatype conflict among bases with ZODB3 or
ZODB4. Both versions define based types in C that are not compatible
with the layout of the string object.  (Perhaps there's a way to make
this work, but I'm not an expert on metatypes.)

> Is whatever-version-I-need stable, and will there be any
> problems in using my current file storage database files
> with that version?
> 
> I just tried something like:
> 
> class MyClass(str, Persistence.Persistent):
>      blah blah blah
> 
> That way I planned to get a persistent string that I can
> attach more attributes to. I have a lot of code assuming
> this object is a string (plenty of 'if object in "asdfgh"'
> etc) but now I suddenly need to have colours etc as well. :-(

Why don't you just use UserString?  It will work with either version
of persistence. you can also add attributes to it.

Jeremy