Adding this expressions #23

wants to merge 1 commit into


None yet
1 participant

I backported the this expression that I introduced to construct3 (which I don't have time to finish). So I decided it would be a good idea to backport it. It's 100% backwards compatible, so there's no harm whatsoever, and it's much more readable and concise than those ugly lambdas.

In short:

  • instead of Field(..., lambda ctx: ctx.length) use Field(..., this.length)
  • Instead of Field(..., lambda ctx: ctx._.length * 4) use Field(..., this._.length * 4)
  • Instead of If(lambda ctx: ctx["foo"] > 17, ...), use If( > 17, ...)

I included a unit test (tests/

By the way, I would suggest moving the tests directory out of the package, e.g.

    tests/  <==
Adding the `this` expression (backported from construct3). The `this`
expression builds an evaluatable (callable) object directly from python
expressions, so it's less verbose and much easier to read and write.
Also, it's compatible with the existing lambda functions. Instead of
doing `lambda ctx: ctx["length"] * 2`, simply use `this.length * 2`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment