[Python-Dev] BaseException pickle issue

Eric Huss ehuss at ironport.com
Sun Apr 1 21:07:23 CEST 2007

> I think that this is a bug, but removing those methods is not the right
> solution.  The __reduce__ method is needed because builtin exceptions
> don't store their attributes in the __dict__ anymore; if you remove it,
> then those attributes will be lost during pickling.  The __setstate__
> method was added to help with unpickling old exceptions, which did store
> all their attributes in the __dict__.  See this patch for details:
> http://www.python.org/sf/1498571
> A better solution would be to move the initial args attribute assignment
> to BaseException.__new__.  See this patch:
> http://www.python.org/sf/1692335
> Could you check if that fixes your problem?

Thanks, it certainly does!

I wrote a very extensive unittest to try out various permutations.  I'm
not sure if there's an expectation that pickled strings of user-defined
exceptions from previous versions work in newer versions.  If you define
your own __init__ method, and try to load a pickled string from 2.4, I
still get a TypeError when trying to unpickle it.  I will send you my test
file directly.  This isn't a problem for me since we don't store pickled


More information about the Python-Dev mailing list