File tree Expand file tree Collapse file tree 2 files changed +8
-7
lines changed
Expand file tree Collapse file tree 2 files changed +8
-7
lines changed Original file line number Diff line number Diff line change @@ -173,12 +173,11 @@ 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- # 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
176+ assert isinstance (cls , type ), \
177+ f"must pass a type, not an instance: '{ cls !r} '"
178+ assert hasattr (cls , "__mro__" ), "'cls' has no attribute '__mro__': "
180179
181- return hasattr ( cls , "__mro__" ) and (
180+ return (
182181 cls is ArrayContainer
183182 or (serialize_container .dispatch (cls )
184183 is not serialize_container .__wrapped__ )) # type:ignore[attr-defined]
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ class ArrayContainerWithStringTypes:
5959 y : "np.ndarray"
6060
6161 with pytest .raises (AssertionError ):
62+ # NOTE: cannot have string annotations in container
6263 dataclass_array_container (ArrayContainerWithStringTypes )
6364
6465 # }}}
@@ -70,8 +71,9 @@ class ArrayContainerWithOptional:
7071 x : np .ndarray
7172 y : Optional [np .ndarray ]
7273
73- cls = dataclass_array_container (ArrayContainerWithOptional )
74- assert cls is not None
74+ with pytest .raises (AssertionError ):
75+ # NOTE: cannot have wrapped annotations (here by `Optional`)
76+ dataclass_array_container (ArrayContainerWithOptional )
7577
7678 # }}}
7779
You can’t perform that action at this time.
0 commit comments