Infinite recursion in __reduce__ when calling original base class reduce, why?

Irmen de Jong irmen.NOSPAM at xs4all.nl
Tue Jun 14 14:17:50 EDT 2011


On 14-6-2011 2:40, Chris Torek wrote:

> 
> Nonetheless, there is something at least slightly suspicious here:
[... snip explanations...]

Many thanks Chris, for the extensive reply. There's some useful knowledge in it.

My idea to call the base class reduce as the default fallback causes the problems:
	return return super(TestClass, self).__reduce__()
If, following your suggestion, I replace that with:
	return self.__class__, (self.name,)
it works fine.
	
By the way, in the meantime I've played around with copyreg.pickle, and that code worked
in all Python implementations I've tried it in. This code feels better too, because it
is possible to simply use
	return self.__reduce__()
as a fallback in it, because we're not touching the object's own __reduce__ in any way.

Anyway thanks again

Irmen



More information about the Python-list mailing list