diff options
author | Damien George <damien.p.george@gmail.com> | 2014-03-03 23:25:08 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-03-03 23:25:08 +0000 |
commit | 25f5a30e73aa64b4a15f60d01c4fe3901bc41be6 (patch) | |
tree | 2e5653319c195b32ae542e8ff3b320e258d46f03 | |
parent | f41fdd05b0c415afd7fc6a1a3f33111f59be43ee (diff) | |
download | micropython-25f5a30e73aa64b4a15f60d01c4fe3901bc41be6.tar.gz micropython-25f5a30e73aa64b4a15f60d01c4fe3901bc41be6.zip |
py: Fix overriding of default arguments.
Addresses issue #327.
-rw-r--r-- | py/objfun.c | 2 | ||||
-rw-r--r-- | tests/basics/fun-defargs2.py | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/py/objfun.c b/py/objfun.c index a94978e3a4..80cee1643b 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -249,7 +249,7 @@ continue2:; mp_obj_t *d = &flat_args[self->n_args - 1]; mp_obj_t *s = &self->extra_args[self->n_def_args - 1]; for (int i = self->n_def_args; i > 0; i--) { - if (*d != MP_OBJ_NULL) { + if (*d == MP_OBJ_NULL) { *d-- = *s--; } } diff --git a/tests/basics/fun-defargs2.py b/tests/basics/fun-defargs2.py new file mode 100644 index 0000000000..c9090a3cd2 --- /dev/null +++ b/tests/basics/fun-defargs2.py @@ -0,0 +1,13 @@ +# overriding default arguments + +def foo(a, b=3): + print(a, b) + +# override with positional +foo(1, 333) + +# override with keyword +foo(1, b=333) + +# override with keyword +foo(a=2, b=333) |