s-leroux / fin

Set of tools for personal investment
MIT License
1 stars 0 forks source link

In some circumstances, the column mini-language requires wrapping the argument in a 1-tuple #22

Closed s-leroux closed 7 months ago

s-leroux commented 7 months ago

https://github.com/s-leroux/fin/blob/1d7dbf85eceb1bebb41be36195dc99180bff6fc7/examples/fin/model/warrant_price_change.py#L40

In some circumstances, the column mini-language requires wrapping the argument in a 1-tuple. This is confusing.

In practice, the following code is ambiguous:

(callable, callable, "X")

Using the infix notation, it can be parsed either as callable(callable(), "X") or callable(callable("X")) or even callable(callable()), "X".

s-leroux commented 7 months ago

The new interpreter introduced in 3161ebf3aff4cf23d8d29e0b31172c116205ddee is right-associative.

So (callable_1, callable_2, "X") is interpreted as (callable_1, (callable_2, "X")).

If callable_2 has to be interpreted as a nullary function, it requires explicit wrapping in a 1-tuple: (callable_1, (callable_2,), "X"). The error-prone part here is the trailing comma required by Python for 1-tuple.

Closing as stale.