Skip to content

Commit fc9172f

Browse files
committed
check cls in is_array_container_type has an mro
1 parent 56cfb40 commit fc9172f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arraycontext/container/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ def is_array_container_type(cls: type) -> bool:
173173
function will say that :class:`numpy.ndarray` is an array container
174174
type, only object arrays *actually are* array containers.
175175
"""
176-
return (
176+
# NOTE: `is_array_container_type` is used in `dataclass_array_container`
177+
# where it looks at field types. The fields can contain typing information
178+
# like `typing.Optional[MyType]`, which does not have an `__mro__` and messes
179+
# up `singledispatch.dispatch`, so we check for that first
180+
181+
return hasattr(cls, "__mro__") and (
177182
cls is ArrayContainer
178183
or (serialize_container.dispatch(cls)
179184
is not serialize_container.__wrapped__)) # type:ignore[attr-defined]

0 commit comments

Comments
 (0)