Skip to content

Commit 21a63b3

Browse files
committed
Improve error message for inconsistent types in _multimap_array_container_impl
1 parent 715b4bf commit 21a63b3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

arraycontext/container/traversal.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,16 @@ def rec(*args_: Any) -> Any:
244244
except NotAnArrayContainerError:
245245
return f(*args_)
246246

247-
assert all(
248-
type(args_[i]) is type(template_ary) for i in container_indices[1:]
249-
), f"expected type '{type(template_ary).__name__}'"
247+
if __debug__: # noqa: SIM102
248+
if not all(
249+
type(args_[i]) is type(template_ary)
250+
for i in container_indices[1:]
251+
):
252+
arg_summary = ", ".join(
253+
f"arg{i+1}: {type(arg)}"
254+
for i, arg in enumerate(args_))
255+
raise TypeError(
256+
f"inconsistent types in multiple traversal: {arg_summary}")
250257

251258
result = []
252259
new_args = list(args_)

test/test_arraycontext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def check_leaf(a, subary1, b, subary2):
802802
for ary in [ary_dof, ary_of_dofs, mat_of_dofs, dc_of_dofs]:
803803
check_leaf(2, ary, 2, ary)
804804

805-
with pytest.raises(AssertionError):
805+
with pytest.raises(TypeError):
806806
rec_multimap_array_container(func_multiple_scalar, 2, ary_dof, 2, dc_of_dofs)
807807

808808
# }}}

0 commit comments

Comments
 (0)