Throw a NotImplementedError for time functions on boards without long ints

Fix for Issue #2812. Instead of reporting a missing attribute for functions such as time.time() and time.mktime(); platforms that do not have long integer support will raise a NotImplementedError
This commit is contained in:
DavePutz 2020-05-08 16:33:26 -05:00 committed by GitHub
parent 4e786fa63a
commit e7fc806034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,6 +188,14 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) {
tm->tm_yday = mp_obj_get_int(elems[7]);
// elems[8] tm_isdst is not supported
}
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
// Function to return a NotImplementedError on platforms that don't
// support long integers
STATIC mp_obj_t time_not_implemented(void) {
mp_raise_NotImplementedError(translate("No long integer support"));
}
MP_DEFINE_CONST_FUN_OBJ_0(time_not_implemented_obj, time_not_implemented);
#endif
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
mp_obj_t MP_WEAK rtc_get_time_source_time(void) {
@ -307,6 +315,12 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_time_obj) },
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_monotonic_ns_obj) },
#endif
#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
{ MP_ROM_QSTR(MP_QSTR_localtime), MP_ROM_PTR(&time_not_implemented_obj) },
{ MP_ROM_QSTR(MP_QSTR_mktime), MP_ROM_PTR(&time_not_implemented_obj) },
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&time_not_implemented_obj) },
{ MP_ROM_QSTR(MP_QSTR_monotonic_ns), MP_ROM_PTR(&time_not_implemented_obj) },
#endif
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);