fix if ExceptionGroup not exist

This commit is contained in:
Cheukting 2022-06-23 15:03:48 +08:00
parent c135a236d3
commit 39339b991d
1 changed files with 13 additions and 1 deletions

View File

@ -56,6 +56,18 @@ if TYPE_CHECKING:
_TracebackStyle = Literal["long", "short", "line", "no", "native", "value", "auto"]
ExceptionGroupTypes: tuple = ()
try:
ExceptionGroupTypes += (ExceptionGroup,)
except NameError:
pass # Is missing for `python<3.10`
try:
import exceptiongroup
ExceptionGroupTypes += (exceptiongroup.ExceptionGroup,)
except ModuleNotFoundError:
pass # No backport is installed
class Code:
"""Wrapper around Python code objects."""
@ -923,7 +935,7 @@ class FormattedExcinfo:
seen: Set[int] = set()
while e is not None and id(e) not in seen:
seen.add(id(e))
if isinstance(e, ExceptionGroup):
if isinstance(e, ExceptionGroupTypes):
reprtraceback = ReprTracebackNative(
traceback.format_exception(
type(e), e, excinfo.traceback[0]._rawentry