This works without the HIGHEST_PROTOCOL
because the older protocols don't use the __new__
constructor for unpickled objects.
But the basic is that you are using the serializing methods of str
while you are adding a new argument to __new__
. The pickle
module nor the builtin str
type has any knowledge of this and it will result in the error shown.
To fix it you should define the __getnewargs__
method and return (self.__class__, self.bar)
which should be sufficient for it to work again.
Documentation on the special methods used by the pickle
module can be found here