pickle does not work properly with cooperative multiple inheritance. Propose: "__getnewkwargs__".

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

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
participants (1)
-
Neil Girdhar