You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "<python-input-0>", line 4, in <module>
pickle.dumps(s)
~~~~~~~~~~~~^^^_pickle.PicklingError: first argument to __newobj__() must be <class 'super'>, not <class '__main__.X'>
when serializing super object
This is because the special methods like __reduce_ex__() are looked up in an instance and translated to a lookup in the underlying object.
This cannot be solved by implementing the __reduce_ex__() method in the super class, because the current behavior is expected when super() is used in the __reduce_ex__() implementation of some subclass. The super class likely should be registered in the global dispatch table.
There may be similar issue with shallow and deep copying.
Previously, copying a super object returned a copy of the instance
invoking super(). Pickling a super object could pickle the instance
invoking super() or fail, depending on its type and protocol.
Now deep copying returns a new super object and pickling pickles the super
object. Shallow copying returns the same super object.
Previously, copying a super object returned a copy of the instance
invoking super(). Pickling a super object could pickle the instance
invoking super() or fail, depending on its type and protocol.
Now deep copying returns a new super object and pickling pickles the super
object. Shallow copying returns the same super object.
Previously, copying a super object returned a copy of the instance
invoking super(). Pickling a super object could pickle the instance
invoking super() or fail, depending on its type and protocol.
Now deep copying returns a new super object and pickling pickles the super
object. Shallow copying returns the same super object.
Feature or enhancement
As was noted in #125714 (comment), the
super
object is not pickleable. For example:Produces a traceback:
This is because the special methods like
__reduce_ex__()
are looked up in an instance and translated to a lookup in the underlying object.This cannot be solved by implementing the
__reduce_ex__()
method in thesuper
class, because the current behavior is expected whensuper()
is used in the__reduce_ex__()
implementation of some subclass. Thesuper
class likely should be registered in the global dispatch table.There may be similar issue with shallow and deep copying.
Linked PRs
The text was updated successfully, but these errors were encountered: