Skip to content

Default args not handled for lambda's #1628

@pfalcon

Description

@pfalcon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions