Message 232135 - Python tracker (original) (raw)

When no efforts were spent to support pickling of instances of Python class, in most cases the class will be pickleable. Default implementation just saves all attributes and this works if all attributes are pickleable. Exceptional special cases:

  1. Classes with slot. In this case an attempt to pickle will raise an exception with explaining message.

  2. Classes with new wish mandatory parameters. In this case the pickling will be silently "successful", but actually data will be not saved and unpickling will fail. See for example , .

But when the class is implemented in C and doesn't expose its attribute in dict, in most cases it is variant (2) -- silent incorrect pickling.

I think we should prevent incorrect pickling by default. It is better to fail loudly. Default reduce could inspect the new method and raise an exception if it has non-optional parameters and the class doesn't implement getnewargs_ex or getnewargs methods. And fail on all classes implemented in C if they don't implement any pickle-related methods.