Skip to content

More user-friendly lambda functions #4

@smarie

Description

@smarie

Our original need was to raise user-friendly errors in case of failed validation. It is very frequent that a validation operation just consists in a few operations, and it is therefore quite convenient to express it as a lambda function. There are two main issues then:

  • it is not easy to retrieve the lambda expression itself so as to display it in a message such as "validation failed: x > 2 returned False".
  • the lambda <vars>: prefix is sometimes a bit cumbersome. Being able to import or create special input symbols so that lambda is implicit would make the code more readable.

For this reason I created mini-lambda but it has some major limitations (one input only, and some python operators can not be used because the corresponding magic method has too much constraints).

Maybe we could propose a PEP about

  • at least string representation for lambda functions (quite easy to specify and implement I guess)
  • and maybe, but this is much harder, about new symbols that could be used to create "implicit lambdas"... Thoughts ?

See also this stackoverflow post

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions