[ZODB-Dev] property broken with/by ZODB?
Chris Cioffi
evenprimes at gmail.com
Tue Aug 17 15:37:56 EDT 2004
I'm downloading the new version as I write this. Thanks Tim!
Chris
On Tue, 17 Aug 2004 15:10:24 -0400, Tim Peters <tim at zope.com> wrote:
> [Chris Cioffi]
> > I'm converting a bunch of dicts into proper classes and am having some
> > problems using the property builtin. When I derive the class from
> > Persistent my properties don't work. Here's an example:
> >
> > import os.path
> >
> > import ZODB
> > from Persistence import Persistent
>
> ....
>
> You didn't say which version of ZODB you're using, but I'm guessing it's
> some flavor of 3.2. Persistent is a Zope ExtensionClass, and
> ExtensionClasses don't play well with many newer Python class features (such
> as properties).
>
> So I wouldn't expect this to work in 3.2.i (or 3.1.i, or ...).
>
> You have a much better chance with ZODB 3.3. Persistent is a vanilla
> new-style Python class in 3.3, so plays much better with new-style class
> features (like properties). To run your code under 3.3b2 (the most recent
> 3.3 pre-release), you need to change
>
> from Persistence import Persistent
>
> to
>
> from persistent import Persistent
>
> Then you get the new-style Persistent base class. There's still an
> ExtensionClass-based version in Zope, but it will no longer ship with ZODB;
> if you try "from Persistence import Persistent" in ZODB 3.3, you get a long
> message, starting with
>
> UserWarning: Couldn't import the ExtensionClass-based base class
>
> There are two possibilities:
>
> 1. You don't care about ExtensionClass. You are importing
> Persistence because that's what you imported in the past.
> In this case, you should really use the persistent package
> instead:
>
> >>> from persistent import Persistent
> >>> from persistent.list import PersistentList
> >>> from persistent.mapping import PersistentMapping
>
> ...
>
> Anyway, I made that change, and then your program displayed:
>
> The Persistent aware obj
> somefile.txt
> The "normal" object
> somefile.txt
>
> under 3.3b2, which is what I figure you wanted.
>
>
--
Still searching for an even prime > 2!
More information about the ZODB-Dev
mailing list