New submission from Serhiy Storchaka:

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 issue21975, issue22955.

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.

----------
messages: 232135
nosy: alexandre.vassalotti, pitrou, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Restrict default picleability

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22995>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to