From 6010add796231979d7bd4c2696a3776e5db69978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Louf?= Date: Mon, 5 Sep 2022 17:09:35 +0200 Subject: [PATCH] Use the current `op` to determine which `etuple` function to use The first argument passed to `etuple` determines which of the registered functions is called. The first argument is generally an `ExpressionTuple`, the etuplized version of the operator. However, when using subclasses of `ExpressionTuple` to customize evaluation, we want `etuple` to depend on the current operator and not its etuplized version. --- etuples/dispatch.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/etuples/dispatch.py b/etuples/dispatch.py index 4c6a435..da94d62 100644 --- a/etuples/dispatch.py +++ b/etuples/dispatch.py @@ -101,6 +101,11 @@ def apply_ExpressionTuple(rator, rands): operator, arguments, term = rator, rands, apply +@dispatch(object) +def etuplize_fn(op): + return etuple + + @dispatch(object) def etuplize( x, @@ -140,6 +145,7 @@ def etuplize_step( return_bad_args=return_bad_args, convert_ConsPairs=convert_ConsPairs, ): + if isinstance(x, ExpressionTuple): yield x return @@ -182,6 +188,6 @@ def etuplize_step( ) et_args.append(e) - yield etuple(et_op, *et_args, evaled_obj=x) + yield etuplize_fn(op)(et_op, *et_args, evaled_obj=x) return trampoline_eval(etuplize_step(x))