Skip to content

Commit 71ebd4b

Browse files
committed
py: Implement UnicodeError.
Still too shy to implement UnicodeEncodeError which was really needed for micropython-lib case.
1 parent 70b3160 commit 71ebd4b

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

py/modbuiltins.c

+3
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,9 @@ STATIC const mp_map_elem_t mp_module_builtins_globals_table[] = {
683683
{ MP_OBJ_NEW_QSTR(MP_QSTR_SyntaxError), (mp_obj_t)&mp_type_SyntaxError },
684684
{ MP_OBJ_NEW_QSTR(MP_QSTR_SystemExit), (mp_obj_t)&mp_type_SystemExit },
685685
{ MP_OBJ_NEW_QSTR(MP_QSTR_TypeError), (mp_obj_t)&mp_type_TypeError },
686+
#if MICROPY_PY_BUILTINS_STR_UNICODE
687+
{ MP_OBJ_NEW_QSTR(MP_QSTR_UnicodeError), (mp_obj_t)&mp_type_UnicodeError },
688+
#endif
686689
{ MP_OBJ_NEW_QSTR(MP_QSTR_ValueError), (mp_obj_t)&mp_type_ValueError },
687690
{ MP_OBJ_NEW_QSTR(MP_QSTR_ZeroDivisionError), (mp_obj_t)&mp_type_ZeroDivisionError },
688691
// Somehow CPython managed to have OverflowError not inherit from ValueError ;-/

py/obj.h

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ extern const mp_obj_type_t mp_type_StopIteration;
369369
extern const mp_obj_type_t mp_type_SyntaxError;
370370
extern const mp_obj_type_t mp_type_SystemExit;
371371
extern const mp_obj_type_t mp_type_TypeError;
372+
extern const mp_obj_type_t mp_type_UnicodeError;
372373
extern const mp_obj_type_t mp_type_ValueError;
373374
extern const mp_obj_type_t mp_type_ZeroDivisionError;
374375

py/objexcept.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,11 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
249249
//MP_DEFINE_EXCEPTION(SystemError, Exception)
250250
MP_DEFINE_EXCEPTION(TypeError, Exception)
251251
MP_DEFINE_EXCEPTION(ValueError, Exception)
252-
//TODO: Implement UnicodeErrors which take arguments
252+
#if MICROPY_PY_BUILTINS_STR_UNICODE
253+
MP_DEFINE_EXCEPTION_BASE(ValueError)
254+
MP_DEFINE_EXCEPTION(UnicodeError, ValueError)
255+
//TODO: Implement more UnicodeError subclasses which take arguments
256+
#endif
253257
/*
254258
MP_DEFINE_EXCEPTION(Warning, Exception)
255259
MP_DEFINE_EXCEPTION_BASE(Warning)

py/qstrdefs.h

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ Q(TypeError)
137137
Q(UnboundLocalError)
138138
Q(ValueError)
139139
Q(ZeroDivisionError)
140+
#if MICROPY_PY_BUILTINS_STR_UNICODE
141+
Q(UnicodeError)
142+
#endif
140143

141144
Q(None)
142145
Q(False)

0 commit comments

Comments
 (0)