From 7b91b2cb0582092e4c696e69288a0e4c3dc0066e Mon Sep 17 00:00:00 2001 From: Joost van Zwieten Date: Wed, 11 Aug 2021 16:22:53 +0200 Subject: [PATCH] fix propagation of AttrError in evaluable.asarray `evaluable.asarray(arg)` converts its `arg` to an `evaluable.Array` by first trying `arg.as_evaluable_array` and if this is absent calling `numpy.array(arg)` (via `Constant`). The attribute `arg.as_evaluable_array` is assumed to be absent if it raises an `AttributeError`. However, if the attribute is a property that somewhere down the road raises `AttributeError`, this should be considered an error and the exception should be propagated. This patch fixes this problem by testing the existence of `as_evaluable_array` on the class using `hasattr`. --- nutils/evaluable.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nutils/evaluable.py b/nutils/evaluable.py index dbe0d0023..81bd2c51b 100644 --- a/nutils/evaluable.py +++ b/nutils/evaluable.py @@ -65,10 +65,8 @@ def simplified(value): asdtype = lambda arg: arg if any(arg is dtype for dtype in (bool, int, float, complex)) else {'f': float, 'i': int, 'b': bool, 'c': complex}[numpy.dtype(arg).kind] def asarray(arg): - try: + if hasattr(type(arg), 'as_evaluable_array'): return arg.as_evaluable_array - except AttributeError: - pass if _containsarray(arg): return stack(arg, axis=0) else: