Skip to content

Commit

Permalink
format_traceback: Return list, as documented, and compatible with CPy…
Browse files Browse the repository at this point in the history
…thon
  • Loading branch information
jepler committed Oct 13, 2022
1 parent 9ecb905 commit febc7a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions shared-bindings/traceback/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ STATIC void traceback_exception_common(bool is_print_exception, mp_print_t *prin
//| tb: Optional[TracebackType] = None,
//| limit: Optional[int] = None,
//| chain: Optional[bool] = True,
//| ) -> str:
//| ) -> List[str]:
//| """Format a stack trace and the exception information.
//|
//| If the exception value is passed in ``exc``, then this exception value and its
Expand Down Expand Up @@ -143,7 +143,8 @@ STATIC mp_obj_t traceback_format_exception(size_t n_args, const mp_obj_t *pos_ar
vstr_t vstr;
vstr_init_print(&vstr, 0, &print);
traceback_exception_common(false, &print, n_args, pos_args, kw_args);
return mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
mp_obj_t output = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
return mp_obj_new_list(1, &output);
}

STATIC MP_DEFINE_CONST_FUN_OBJ_KW(traceback_format_exception_obj, 0, traceback_format_exception);
Expand Down
2 changes: 1 addition & 1 deletion tests/circuitpython/traceback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def fun():
print("\nLimit=0 Trace:")
traceback.print_exception(None, exc, exc.__traceback__, limit=0)
print("\nLimit=-1 Trace:")
print(traceback.format_exception(None, exc, exc.__traceback__, limit=-1), end="")
print("".join(traceback.format_exception(None, exc, exc.__traceback__, limit=-1)), end="")


class NonNativeException(Exception):
Expand Down

0 comments on commit febc7a8

Please sign in to comment.