Skip to content

Commit e53b2ee

Browse files
committed
fixed up handling of iterables
1 parent 9c1a0d5 commit e53b2ee

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

pydra/utils/typing.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ def expand_pattern(t):
108108
# If no args were provided, or those arguments were an ellipsis
109109
assert isinstance(origin, type)
110110
return origin
111+
if origin not in (ty.Union, type) and not issubclass(origin, ty.Iterable):
112+
raise TypeError(
113+
f"Don't know how to handle args ({args}) for {origin} type"
114+
)
111115
return (origin, [expand_pattern(a) for a in args])
112116

113117
self.tp = tp
@@ -143,7 +147,7 @@ def __call__(self, obj: ty.Any) -> ty.Union[T, LazyField[T]]:
143147
coerced = attr.NOTHING # type: ignore[assignment]
144148
elif isinstance(obj, LazyField):
145149
self.check_type(obj.type)
146-
coerced = obj
150+
coerced = obj # type: ignore
147151
elif isinstance(obj, StateArray):
148152
coerced = StateArray(self(o) for o in obj) # type: ignore[assignment]
149153
else:
@@ -184,14 +188,11 @@ def expand_and_coerce(obj, pattern: ty.Union[type, tuple]):
184188
raise TypeError(
185189
f"Could not coerce to {type_} as {obj} is not iterable{msg}"
186190
) from e
187-
if issubclass(origin, ty.Tuple):
191+
if issubclass(origin, tuple):
188192
return coerce_tuple(type_, obj_args, pattern_args)
189193
if issubclass(origin, ty.Iterable):
190194
return coerce_sequence(type_, obj_args, pattern_args)
191-
else:
192-
assert (
193-
False
194-
), f"Don't know how to handle args ({pattern_args}) for {origin} type"
195+
assert False, f"Coercion from {obj} to {pattern} is not handled"
195196

196197
def coerce_basic(obj, pattern):
197198
"""Coerce an object to a "basic types" like `int`, `float`, `bool`, `Path`

0 commit comments

Comments
 (0)