This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author iritkatriel
Recipients 4-launchpad-kalvdans-no-ip-org, Kirill Matsaberydze, alexandre.vassalotti, benoit-pierre, cryvate, georg.brandl, iritkatriel, jaraco, orivej, sbt, slallum, zseil
Date 2022-01-06.15:54:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1641484453.89.0.640915707568.issue32696@roundup.psfhosted.org>
In-reply-to
Content
This isn't really an issue with exceptions, it's just that __reduce__ goes out of sync with the object's constructor signature. Here's a simple example of the same:

class Base:
   def __init__(self, msg):
       self.msg = msg

   def __reduce__(self):
       return type(self), (self.msg,)

class Derived(Base):
   def __init__(self, a, b):
       super().__init__(f'{a}|{b}')

x = Derived('a', 'b')
assert x.msg == 'a|b'
y = pickle.dumps(x, -1)
z = pickle.loads(y)

-------------------------------------------
Output:

Traceback (most recent call last):
  File "/Users/iritkatriel/src/cpython/zz.py", line 22, in <module>
    z = pickle.loads(y)
        ^^^^^^^^^^^^^^^
TypeError: Derived.__init__() missing 1 required positional argument: 'b'

If I define __reduce__ on Derived to return an arg tuple of the right length for its __init__, it works:

class Derived(Base):
   def __init__(self, a, b):
       super().__init__(f'{a}|{b}')

   def __reduce__(self):
       return type(self), tuple(self.msg.split('|'))

But note that this is not something we could make the base class do, it has no way of finding out what the semantics of the derived class constructor args are.
History
Date User Action Args
2022-01-06 15:54:13iritkatrielsetrecipients: + iritkatriel, georg.brandl, jaraco, zseil, alexandre.vassalotti, orivej, sbt, cryvate, slallum, Kirill Matsaberydze, benoit-pierre, 4-launchpad-kalvdans-no-ip-org
2022-01-06 15:54:13iritkatrielsetmessageid: <1641484453.89.0.640915707568.issue32696@roundup.psfhosted.org>
2022-01-06 15:54:13iritkatriellinkissue32696 messages
2022-01-06 15:54:13iritkatrielcreate