Skip to content

Commit febc7a8

Browse files
committed
format_traceback: Return list, as documented, and compatible with CPython
1 parent 9ecb905 commit febc7a8

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

shared-bindings/traceback/__init__.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin
110110
//| tb: Optional[TracebackType] = None,
111111
//| limit: Optional[int] = None,
112112
//| chain: Optional[bool] = True,
113-
//| ) -> str:
113+
//| ) -> List[str]:
114114
//| """Format a stack trace and the exception information.
115115
//|
116116
//| If the exception value is passed in ``exc``, then this exception value and its
@@ -143,7 +143,8 @@ STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_ar
143143
vstr_t vstr;
144144
vstr_init_print(&vstr, 0, &print);
145145
traceback_exception_common(false, &print, n_args, pos_args, kw_args);
146-
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
146+
mp_obj_t output = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
147+
return mp_obj_new_list(1, &output);
147148
}
148149

149150
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_format_exception);

tests/circuitpython/traceback_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def fun():
2121
print("\nLimit=0 Trace:")
2222
traceback.print_exception(None, exc, exc.__traceback__, limit=0)
2323
print("\nLimit=-1 Trace:")
24-
print(traceback.format_exception(None, exc, exc.__traceback__, limit=-1), end="")
24+
print("".join(traceback.format_exception(None, exc, exc.__traceback__, limit=-1)), end="")
2525

2626

2727
class NonNativeException(Exception):

0 commit comments

Comments
 (0)