summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-12 13:42:51 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-12 13:42:51 +0000
commit29e9db0c587145a8823227635734924896cdc4d1 (patch)
tree5154dbd6aefce46f4ea015a2891efe95d46383f7 /tests/basics
parentbb7f5b55010a3957bad30fbb505664e385b290b6 (diff)
downloadmicropython-29e9db0c587145a8823227635734924896cdc4d1.tar.gz
micropython-29e9db0c587145a8823227635734924896cdc4d1.zip
py: Fix compiler to handle lambdas used as default arguments.
Addresses issue #1709.
Diffstat (limited to 'tests/basics')
-rw-r--r--tests/basics/fun_defargs.py9
-rw-r--r--tests/basics/fun_kwonly.py7
2 files changed, 16 insertions, 0 deletions
diff --git a/tests/basics/fun_defargs.py b/tests/basics/fun_defargs.py
index ed25f5739d..1466c44094 100644
--- a/tests/basics/fun_defargs.py
+++ b/tests/basics/fun_defargs.py
@@ -1,3 +1,5 @@
+# testing default args to a function
+
def fun1(val=5):
print(val)
@@ -18,3 +20,10 @@ try:
fun2(1, 2, 3, 4)
except TypeError:
print("TypeError")
+
+# lambda as default arg (exposes nested behaviour in compiler)
+def f(x=lambda:1):
+ return x()
+print(f())
+print(f(f))
+print(f(lambda:2))
diff --git a/tests/basics/fun_kwonly.py b/tests/basics/fun_kwonly.py
index bdff3a8210..7694c8ddca 100644
--- a/tests/basics/fun_kwonly.py
+++ b/tests/basics/fun_kwonly.py
@@ -57,3 +57,10 @@ def f(a, *b, c):
f(1, c=2)
f(1, 2, c=3)
f(a=1, c=3)
+
+# lambda as kw-only arg (exposes nested behaviour in compiler)
+def f(*, x=lambda:1):
+ return x()
+print(f())
+print(f(x=f))
+print(f(x=lambda:2))