py/objexcept: make_new: Convert to support separate __new__ vs __init__ phases
@@ -188,7 +188,11 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin
}
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
+ MP_MAKE_NEW_GET_ONLY_FLAGS();
+ // BaseException.__new__ accepts (and ignores) kwargs, while .__init__ - doesn't accept.
+ if (!only_new) {
mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false);
+ }
// Try to allocate memory for the exception, with fallback to emergency exception object
mp_obj_exception_t *o_exc = m_new_obj_maybe(mp_obj_exception_t);
@@ -200,6 +204,9 @@ mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, siz
o_exc->base.type = type;
o_exc->traceback_data = NULL;
+ // CPython actually captures positional args in __new__, so we keep
+ // running for both only_new & only_init.
+
mp_obj_tuple_t *o_tuple;
if (n_args == 0) {
// No args, can use the empty tuple straightaway
