[Python-ideas] pickle does not work properly with cooperative multiple inheritance. Propose: "__getnewkwargs__".

Neil Girdhar mistersheik at gmail.com
Wed Sep 18 21:12:13 CEST 2013

An alternative is to allow __getnewargs__ to return a "PassedArgSpec" as I 
described in another idea.

On Wednesday, September 18, 2013 12:21:37 PM UTC-4, Neil Girdhar wrote:
> My understanding of cooperative multiple inheritance is that a class often 
> doesn't know how your parent classes want to be constructed, pickled, etc. 
> and so it delegates to its parents using super.
> In general, constructors can accept keyword arguments, and forward their 
> unused arguments to parents effortlessly:
> class A(B):
>     def __init__(self, x, **kwargs):
>          super().__init__(**kwargs)
> will extract x and forward kwargs.
> Unfortunately, the same mechanism is not easily available for pickling 
> because __getnewargs__ returns only a tuple.  If there were a 
> __getnewkwargs__ method, then we could have
> class A:
>     def _getnewkwargs__(self):
>          return {**super().__getnewkwargs(), a=self.a, b=self.b}  # (new 
> unpacking from PEP448)
> Note how additional kwargs are added to the dict of kwargs specified by 
> the parent objects.
> Best,
> Neil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130918/1c4357a0/attachment.html>

More information about the Python-ideas mailing list