<DRAFT> Preserve special attributes of built-in exceptions#86
<DRAFT> Preserve special attributes of built-in exceptions#86VmirGerts wants to merge 2 commits intoionelmc:masterfrom
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.
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