-
Notifications
You must be signed in to change notification settings - Fork 38
<DRAFT> Preserve special attributes of built-in exceptions #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
<DRAFT> Preserve special attributes of built-in exceptions #86
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #86 +/- ##
==========================================
- Coverage 96.96% 96.22% -0.75%
==========================================
Files 9 9
Lines 758 768 +10
Branches 53 47 -6
==========================================
+ Hits 735 739 +4
- Misses 18 25 +7
+ Partials 5 4 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| func = type(obj) | ||
| # Detect busted objects: they have a custom __init__ but no __reduce__. | ||
| # This also means the resulting exceptions may be a bit "dulled" down - the args from __reduce__ are discarded. | ||
| if func.__reduce__ in builtin_reducers and func.__init__ not in builtin_inits: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To elaborate a bit on the change:
Having the if func.__reduce__ in builtin_reducers and func.__init__ not in builtin_inits check makes several built-in exceptions fall in the first if-branch, e.g. SystemExit, NameError, StopIteration.
To not process each of them separately, _get_public_class_attributes is used to get all public class attributes (also of the base classes).
This way, having the second branch looks not really necessary.
Note: one could check if an exception is a built-in exception and then just rely on the "native" reduce function. But this also doesn't work always. For example NameError.__reduce__ doesn't preserve the "name" class-attribute.
TODO
see: #87