Skip to content

Commit 3215b85

Browse files
authored
Merge pull request adafruit#728 from jepler/double-splat-crash-circuitpython
py/bc: Turn assertion error into exception
2 parents d65ea99 + 853f7ac commit 3215b85

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

py/bc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw
190190
for (size_t i = 0; i < n_kw; i++) {
191191
// the keys in kwargs are expected to be qstr objects
192192
mp_obj_t wanted_arg_name = kwargs[2 * i];
193+
if(MP_UNLIKELY(!MP_OBJ_IS_QSTR(wanted_arg_name))) {
194+
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
195+
mp_raise_TypeError("unexpected keyword argument");
196+
#else
197+
mp_raise_TypeError("keywords must be strings");
198+
#endif
199+
}
193200
for (size_t j = 0; j < n_pos_args + n_kwonly_args; j++) {
194201
if (wanted_arg_name == arg_names[j]) {
195202
if (code_state->state[n_state - 1 - j] != MP_OBJ_NULL) {

tests/basics/fun_calldblstar.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ def f(self, a, b):
1515
a = A()
1616
a.f(1, **{'b':2})
1717
a.f(1, **{'b':val for val in range(1)})
18+
19+
try:
20+
f(1, **{len: 1})
21+
except TypeError:
22+
print(True)
23+
else:
24+
print(False)

0 commit comments

Comments
 (0)