py/objset: Include the failed key in a KeyError raised from set.remove.

This commit is contained in:
Damien George 2017-10-03 18:03:06 +11:00
parent 2ac1364688
commit 1394258f37
2 changed files with 3 additions and 3 deletions

View File

@ -380,7 +380,7 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) {
check_set(self_in);
mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in);
if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) {
nlr_raise(mp_obj_new_exception(&mp_type_KeyError));
nlr_raise(mp_obj_new_exception_arg1(&mp_type_KeyError, item));
}
return mp_const_none;
}

View File

@ -4,8 +4,8 @@ print(s.remove(1))
print(list(s))
try:
print(s.remove(1), "!!!")
except KeyError:
pass
except KeyError as er:
print('KeyError', er.args[0])
else:
print("failed to raise KeyError")