Merge pull request #728 from jepler/double-splat-crash-circuitpython

py/bc: Turn assertion error into exception
This commit is contained in:
Scott Shawcroft 2018-03-31 09:57:25 -07:00 committed by GitHub
commit 3215b85568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -190,6 +190,13 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
for (size_t i = 0; i < n_kw; i++) {
// the keys in kwargs are expected to be qstr objects
mp_obj_t wanted_arg_name = kwargs[2 * i];
if(MP_UNLIKELY(!MP_OBJ_IS_QSTR(wanted_arg_name))) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
mp_raise_TypeError("unexpected keyword argument");
#else
mp_raise_TypeError("keywords must be strings");
#endif
}
for (size_t j = 0; j < n_pos_args + n_kwonly_args; j++) {
if (wanted_arg_name == arg_names[j]) {
if (code_state->state[n_state - 1 - j] != MP_OBJ_NULL) {

View File

@ -15,3 +15,10 @@ class A:
a = A()
a.f(1, **{'b':2})
a.f(1, **{'b':val for val in range(1)})
try:
f(1, **{len: 1})
except TypeError:
print(True)
else:
print(False)