Skip to content

Commit 3c20bef

Browse files
committed
Improve error message on nested generic types
1 parent 36ceced commit 3c20bef

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

python/coglet/adt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,19 @@ def from_type(tpe: type):
107107
t_args = typing.get_args(tpe)
108108
assert len(t_args) == 1, 'list must have one type argument'
109109
elem_t = t_args[0]
110+
# Fail fast to avoid the cryptic "unsupported Cog type" error later with elem_t
111+
nested_t = typing.get_origin(elem_t)
112+
assert nested_t is None, f'List cannot have nested type {nested_t}'
110113
repetition = Repetition.REPEATED
111114
elif typing.get_origin(tpe) is Union:
112115
t_args = typing.get_args(tpe)
113116
assert len(t_args) == 2 and type(None) in t_args, (
114117
f'unsupported union type {tpe}'
115118
)
116119
elem_t = t_args[0] if t_args[1] is type(None) else t_args[0]
120+
# Fail fast to avoid the cryptic "unsupported Cog type" error later with elem_t
121+
nested_t = typing.get_origin(elem_t)
122+
assert nested_t is None, f'Optional cannot have nested type {nested_t}'
117123
repetition = Repetition.OPTIONAL
118124
else:
119125
elem_t = tpe

0 commit comments

Comments
 (0)