exceptiongroup
exceptiongroup copied to clipboard
native except handler API
trafficstars
This PR is a prototype implementation of #20. Notable additions and changes include:
ExceptionGroupis "Generic" and can be specialised by exceptions. This allows catching specific groups, e.g.except ExceptionGroup[KeyError, TypeError] as exc_group:.- Added new metaclass to implement
ExceptionGroup[A, B, C]andissubclass(exc_group, ExceptionGroup[ABC]). ExceptionGroupattributes.exceptionsand.sourcesare tuples instead of lists. This is intended to prevent inconsistencies between the type and its attributes.
This PR does not change:
ExceptionGrouphaving.message,.exceptionsand.sourcesattributes.- A bare
except ExceptionGroup:catching all possibleExceptionGroups. - Existing API for splitting/catching sub-exceptions.
- There is no "sub-handler" API as part of this PR.
Codecov Report
Merging #21 into master will increase coverage by
3.32%. The diff coverage is82.85%.
@@ Coverage Diff @@
## master #21 +/- ##
==========================================
+ Coverage 66.55% 69.88% +3.32%
==========================================
Files 11 12 +1
Lines 311 425 +114
Branches 28 49 +21
==========================================
+ Hits 207 297 +90
- Misses 101 115 +14
- Partials 3 13 +10
| Impacted Files | Coverage Δ | |
|---|---|---|
| exceptiongroup/_tests/test_exceptiongroup.py | 88.76% <73.68%> (-11.24%) |
:arrow_down: |
| exceptiongroup/_exception_group.py | 85.85% <85.85%> (ø) |
|
| exceptiongroup/__init__.py | 100.00% <100.00%> (ø) |
|
| exceptiongroup/_monkeypatch.py | 31.25% <100.00%> (ø) |
|
| exceptiongroup/_tools.py | 56.06% <100.00%> (ø) |
As a first draft, this is basically done. Let me know if there is anything else that I should add, or something that needs clarification or discussing.