You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IndexError: tuple index out of range when unstructure dataclass with typing.List annotation #209
Traceback (most recent call last):
File "test.py", line 11, in <module>
print(cattr.unstructure(A(texts=[])))
File "python3.8/site-packages/cattr/converters.py", line 197, in unstructure
return self._unstructure_func.dispatch(
File "python3.8/site-packages/cattr/dispatch.py", line 49, in _dispatch
return self._function_dispatch.dispatch(cl)
File "python3.8/site-packages/cattr/dispatch.py", line 126, in dispatch
return handler(typ)
File "python3.8/site-packages/cattr/converters.py", line 722, in gen_unstructure_attrs_fromdict
h = make_dict_unstructure_fn(
File "python3.8/site-packages/cattr/gen.py", line 125, in make_dict_unstructure_fn
handler = converter._unstructure_func.dispatch(t)
File "python3.8/site-packages/cattr/dispatch.py", line 49, in _dispatch
return self._function_dispatch.dispatch(cl)
File "python3.8/site-packages/cattr/dispatch.py", line 126, in dispatch
return handler(typ)
File "python3.8/site-packages/cattr/converters.py", line 754, in gen_unstructure_iterable
h = make_iterable_unstructure_fn(
File "python3.8/site-packages/cattr/gen.py", line 339, in make_iterable_unstructure_fn
type_arg = get_args(cl)[0]
IndexError: tuple index out of range
Replace List -> List[Any] or List -> Optional[List] fix this problem.
Activity
Tinche commentedon Jan 19, 2022
Ah I forgot to support the bare
List. If you were using Python 3.9+ I would suggest using:I can add a fix for this, it's not hard, but with all the possible ways of writing type annotations it's going to be tricky to get em all.
Thanks for the report.
Tinche commentedon Jan 20, 2022
Fixed on main, alongside a test.
chore(deps): Update cattrs requirement from <1.11,>=1.8 to >=1.8,<22.…
chore(deps): Update cattrs requirement from <22.2,>=1.8 to >=1.8,<22.…