Skip to content

Commit

Permalink
py/modbuiltins: In built-in dir make use of mp_load_method_protected.
Browse files Browse the repository at this point in the history
This gives dir() better behaviour when listing the attributes of a user
type that defines __getattr__: it will now not list those attributes for
which __getattr__ raises AttributeError (meaning the attribute is not
supported by the object).
  • Loading branch information
dpgeorge committed May 10, 2018
1 parent 7241d90 commit 29d28c2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion py/modbuiltins.c
Expand Up @@ -188,7 +188,7 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) {
size_t nqstr = QSTR_TOTAL();
for (size_t i = MP_QSTR_ + 1; i < nqstr; ++i) {
mp_obj_t dest[2];
mp_load_method_maybe(args[0], i, dest);
mp_load_method_protected(args[0], i, dest, false);
if (dest[0] != MP_OBJ_NULL) {
mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(i));
}
Expand Down

0 comments on commit 29d28c2

Please sign in to comment.