diff --git a/py/mpconfig.h b/py/mpconfig.h index 9f541ef705..e92e4c45d0 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -462,6 +462,11 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_RANGE_ATTRS (1) #endif +// Whether to support timeout exceptions (like socket.timeout) +#ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR +#define MICROPY_PY_BUILTINS_TIMEOUTERROR (0) +#endif + // Whether to support complete set of special methods // for user classes, otherwise only the most used #ifndef MICROPY_PY_ALL_SPECIAL_METHODS diff --git a/py/obj.h b/py/obj.h index 7275886c76..10a678e83b 100644 --- a/py/obj.h +++ b/py/obj.h @@ -426,6 +426,7 @@ extern const mp_obj_type_t mp_type_MemoryError; extern const mp_obj_type_t mp_type_NameError; extern const mp_obj_type_t mp_type_NotImplementedError; extern const mp_obj_type_t mp_type_OSError; +extern const mp_obj_type_t mp_type_TimeoutError; extern const mp_obj_type_t mp_type_OverflowError; extern const mp_obj_type_t mp_type_RuntimeError; extern const mp_obj_type_t mp_type_StopIteration; diff --git a/py/objexcept.c b/py/objexcept.c index 6c108d99cb..75369bac7c 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -221,8 +221,11 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(UnboundLocalError, NameError) */ MP_DEFINE_EXCEPTION(OSError, Exception) - /* +#if MICROPY_PY_BUILTINS_TIMEOUTERROR MP_DEFINE_EXCEPTION_BASE(OSError) + MP_DEFINE_EXCEPTION(TimeoutError, OSError) +#endif + /* MP_DEFINE_EXCEPTION(BlockingIOError, OSError) MP_DEFINE_EXCEPTION(ChildProcessError, OSError) MP_DEFINE_EXCEPTION(ConnectionError, OSError) @@ -235,7 +238,6 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(NotADirectoryError, OSError) MP_DEFINE_EXCEPTION(PermissionError, OSError) MP_DEFINE_EXCEPTION(ProcessLookupError, OSError) - MP_DEFINE_EXCEPTION(TimeoutError, OSError) MP_DEFINE_EXCEPTION(FileExistsError, OSError) MP_DEFINE_EXCEPTION(FileNotFoundError, OSError) MP_DEFINE_EXCEPTION(ReferenceError, Exception) diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 2f51d470dd..367aea17bd 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -140,6 +140,9 @@ Q(MemoryError) Q(NameError) Q(NotImplementedError) Q(OSError) +#if MICROPY_PY_BUILTINS_TIMEOUTERROR +Q(TimeoutError) +#endif Q(OverflowError) Q(RuntimeError) Q(SyntaxError)