exceptiongroup icon indicating copy to clipboard operation
exceptiongroup copied to clipboard

native except handler API

Open maxfischer2781 opened this issue 5 years ago • 2 comments
trafficstars

This PR is a prototype implementation of #20. Notable additions and changes include:

  • ExceptionGroup is "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] and issubclass(exc_group, ExceptionGroup[ABC]).
  • ExceptionGroup attributes .exceptions and .sources are tuples instead of lists. This is intended to prevent inconsistencies between the type and its attributes.

This PR does not change:

  • ExceptionGroup having .message, .exceptions and .sources attributes.
  • A bare except ExceptionGroup: catching all possible ExceptionGroups.
  • Existing API for splitting/catching sub-exceptions.
  • There is no "sub-handler" API as part of this PR.

maxfischer2781 avatar Jun 19 '20 07:06 maxfischer2781

Codecov Report

Merging #21 into master will increase coverage by 3.32%. The diff coverage is 82.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%> (ø)

codecov[bot] avatar Jun 19 '20 21:06 codecov[bot]

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.

maxfischer2781 avatar Aug 04 '20 20:08 maxfischer2781