summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2018-03-30 17:10:45 -0500
committerJeff Epler <jepler@gmail.com>2018-03-31 08:44:29 -0500
commit853f7ac4d001d2098a4f25305e235f5d0e7c26c8 (patch)
tree458d7f4e6f047f84ef027e38b384e0d5afe49bb1
parent1eba5804434a8acc182c23aadf5b5a5dcbe901fa (diff)
py/bc: Turn assertion error into exception
-rw-r--r--py/bc.c7
-rw-r--r--tests/basics/fun_calldblstar.py7
2 files changed, 14 insertions, 0 deletions
diff --git a/py/bc.c b/py/bc.c
index 381daa24d..442a29771 100644
--- a/py/bc.c
+++ b/py/bc.c
@@ -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) {
diff --git a/tests/basics/fun_calldblstar.py b/tests/basics/fun_calldblstar.py
index aae9828cf..15038b2f5 100644
--- a/tests/basics/fun_calldblstar.py
+++ b/tests/basics/fun_calldblstar.py
@@ -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)