Skip to content

Commit ff3f742

Browse files
committed
Fix format_exception on py<3.10
1 parent ebd2348 commit ff3f742

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

atomdb/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import asyncio
1212
import enum
1313
import logging
14+
import sys
1415
import traceback
1516
from base64 import b64decode, b64encode
1617
from collections.abc import MutableMapping
@@ -57,6 +58,16 @@
5758

5859
PRIMITIVE_TYPES = (int, float, bool, str)
5960

61+
if sys.version_info >= (3, 10):
62+
63+
def format_exception(e: Exception) -> str:
64+
return "".join(traceback.format_exception(e))
65+
66+
else:
67+
68+
def format_exception(e: Exception) -> str:
69+
return "".join(traceback.format_exception(e.__class__, e, e.__traceback__))
70+
6071

6172
def find_subclasses(cls: Type[T]) -> ListType[Type[T]]:
6273
"""Finds subclasses of the given class"""
@@ -769,7 +780,7 @@ def __log_restore_error__(
769780
f"\nRef: {self.__ref__}"
770781
f"\nScope: {pformat(scope)}"
771782
f"\nState: {pformat(state)}"
772-
f"\n{''.join(traceback.format_exception(e))}"
783+
f"\n{format_exception(e)}"
773784
)
774785

775786
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)