Skip to content

(errors) Correctly set BaseException.args and make them pickable#666

Merged
Tinche merged 3 commits intopython-attrs:mainfrom
raabf:fix-exceptions-pickable
Jul 2, 2025
Merged

(errors) Correctly set BaseException.args and make them pickable#666
Tinche merged 3 commits intopython-attrs:mainfrom
raabf:fix-exceptions-pickable

Conversation

@raabf
Copy link
Contributor

@raabf raabf commented Jul 2, 2025

BaseExceptions subclasses need all parameters of their __init__ methods to be passed to BaseExceptions.__init__, see BaseException.args for that.

This MR will correct the super().__init__ call.

This will also make the Exceptions pickable, which I need for a cache and for multiprocessing.

The interface does not change with this MR.

But for ForbiddenExtraKeysError I moved the

"Extra fields in constructor for {self.cl.__name__}: {', '.join(self.extra_fields)}"

string to __str__ instead of storing it in the object as attribute. As this is a fixed string for the class (which means it does not need be stored) and will be used when actually "" was passed to the constructor, I think this makes more sense.

@raabf raabf force-pushed the fix-exceptions-pickable branch from 919b0d1 to 50a9a99 Compare July 2, 2025 14:37
@Tinche
Copy link
Member

Tinche commented Jul 2, 2025

Great job!

@Tinche Tinche merged commit f5d0594 into python-attrs:main Jul 2, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants