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 douglas-raillard-arm
Recipients douglas-raillard-arm
Date 2021-03-10.11:47:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615376871.09.0.380975849727.issue43460@roundup.psfhosted.org>
In-reply-to
Content
The solution based on the signature is something along those lines:

    class E(BaseException):
        def __new__(cls, *args, **kwargs):
            """
            Fix exception copying.

            Turn all the keyword arguments into positional arguments, so that the
            :exc:`BaseException` machinery has all the parameters for a valid call
            to ``__new__``, instead of missing all the keyword arguments.
            """
            sig = inspect.signature(cls.__init__)
            bound_args = sig.bind_partial(*args, **kwargs)
            bound_args.apply_defaults()
            args = tuple(bound_args.arguments.values())
            return super().__new__(cls, *args)

        def __init__(self, x):
            self.x=x

But there are a many shortcomings to that approach:

 * What if super().__new__() consumes arguments before passing the rest to __init__() ? This fix is blind to that since it only cares about __init__ signature

 * What if inspect.signature() does not provide a signature (extension modules) ?

 * Defaults are "hardcoded" in the args, so the object will always be restored with the defaults of the time it was created. This is a breaking change, as currently the defaults used when restoring the instance are the current ones.

 * Also uses more memory for args (and for pickle files), since it contains all the defaults
History
Date User Action Args
2021-03-10 11:47:51douglas-raillard-armsetrecipients: + douglas-raillard-arm
2021-03-10 11:47:51douglas-raillard-armsetmessageid: <1615376871.09.0.380975849727.issue43460@roundup.psfhosted.org>
2021-03-10 11:47:51douglas-raillard-armlinkissue43460 messages
2021-03-10 11:47:50douglas-raillard-armcreate