-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Default args not handled for lambda's #1628
Copy link
Copy link
Closed
Labels
Description
Python's bound-by-reference variables in closures are pretty broken from functional point of view. The way to get around that and proper functional (by value) binding is to use default args:
# x & y will be bound by value
lambda z, x=x, y=y: f(x, y, z)
And default args for lambdas is exactly what doesn't work in uPy:
>>> f = lambda x=y: x
# No error
>>> f = lambda x=1: x
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: <lambda>() takes 1 positional arguments but 0 were given
Reactions are currently unavailable