From e292296d52800939e70513e33ec456518330c4ad Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 7 Apr 2020 22:48:43 +1000 Subject: [PATCH] py/objexcept: Remove optional TimeoutError exception. TimeoutError was added back in 077812b2abe3f5e5325194f9694dad7eb38186dd for the cc3200 port. In f522849a4d5a978ac3d322d71a755f75d07e8ce6 the cc3200 port enabled use of it in the socket module aliased to socket.timeout. So it was never added to the builtins. Then it was replaced by OSError(ETIMEDOUT) in 047af9b10bfc6b0ec412f8450c6bec10ab95254b. The esp32 port enables this exception, since the very beginning of that port, but it could never be accessed because it's not in builtins. It's being removed: 1) to not encourage its use; 2) because there are a lot of other OSError subclasses which are not defined at all, and having TimeoutError is a bit inconsistent. Note that ports can add anything to the builtins via MICROPY_PORT_BUILTINS. And they can also define their own exceptions using the MP_DEFINE_EXCEPTION() macro. --- ports/esp32/mpconfigport.h | 1 - py/mpconfig.h | 5 ----- py/obj.h | 1 - py/objexcept.c | 4 +--- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 32968eed2d..72ecfadc6b 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -78,7 +78,6 @@ #define MICROPY_PY_BUILTINS_PROPERTY (1) #define MICROPY_PY_BUILTINS_RANGE_ATTRS (1) #define MICROPY_PY_BUILTINS_ROUND_INT (1) -#define MICROPY_PY_BUILTINS_TIMEOUTERROR (1) #define MICROPY_PY_ALL_SPECIAL_METHODS (1) #define MICROPY_PY_BUILTINS_COMPILE (1) #define MICROPY_PY_BUILTINS_ENUMERATE (1) diff --git a/py/mpconfig.h b/py/mpconfig.h index d96687b813..c2352bbdd2 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -959,11 +959,6 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_ROUND_INT (0) #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, or only the most used ones. "Inplace" methods are // controlled by MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS below. diff --git a/py/obj.h b/py/obj.h index 969f3033b9..b282c63db0 100644 --- a/py/obj.h +++ b/py/obj.h @@ -650,7 +650,6 @@ 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_StopAsyncIteration; diff --git a/py/objexcept.c b/py/objexcept.c index 594c4c650f..59a0557b13 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -303,9 +303,6 @@ MP_DEFINE_EXCEPTION(Exception, BaseException) MP_DEFINE_EXCEPTION(UnboundLocalError, NameError) */ MP_DEFINE_EXCEPTION(OSError, Exception) -#if MICROPY_PY_BUILTINS_TIMEOUTERROR - MP_DEFINE_EXCEPTION(TimeoutError, OSError) -#endif /* MP_DEFINE_EXCEPTION(BlockingIOError, OSError) MP_DEFINE_EXCEPTION(ChildProcessError, OSError) @@ -319,6 +316,7 @@ 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)