Skip to content

Commit

Permalink
fix propagation of AttrError in evaluable.asarray
Browse files Browse the repository at this point in the history
`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`.
  • Loading branch information
joostvanzwieten committed Aug 18, 2021
1 parent 1a67b05 commit 7b91b2c
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions nutils/evaluable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7b91b2c

Please sign in to comment.