Skip to content

Commit 6a833a7

Browse files
committed
modbuiltins: Catch most exceptions during dir()
This helps with Python-compatibility (see issue #4171) but doesn't completely resolve it. Now, `dir()` still computes any properties of the underlying object, HOWEVER, if the property raises an exception this expression is captured. This ability to capture exceptions always existed in `mp_load_method_protected`, we just need to turn it on via the `catch_all_exc` boolean parameter.
1 parent a055113 commit 6a833a7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

py/modbuiltins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) {
190190
// Implemented by probing all possible qstrs with mp_load_method_maybe
191191
size_t nqstr = QSTR_TOTAL();
192192
for (size_t i = MP_QSTR_ + 1; i < nqstr; ++i) {
193-
mp_obj_t dest[2];
194-
mp_load_method_protected(args[0], i, dest, false);
193+
mp_obj_t dest[2] = {};
194+
mp_load_method_protected(args[0], i, dest, true);
195195
if (dest[0] != MP_OBJ_NULL) {
196196
#if MICROPY_PY_ALL_SPECIAL_METHODS
197197
// Support for __dir__: see if we can dispatch to this special method

0 commit comments

Comments
 (0)