tuple, list and Color handling is a bit awkward
Currently we make special cases for when we want something as a tuple
, list
or Color
in our Pydantic types
# if it's not one of our dataclasses most often we just want to pass
# the first and only item to `field_type` but sometimes we want to
# make a tuple or something similar from the list of args
# e.g. `["start", 1.0, 1.0]` -> `{"start": tuple([1.0, 1.0])}`
if field_type_outer is tuple:
kwargs[kw] = tuple(exp[0])
elif field_type_outer is list:
kwargs[kw] = list(exp[0])
elif field_type is Color:
kwargs[kw] = Color(exp[0])
This awkwardness is then passed down to when we e.g. want to handle Union
types.
# union types are tried till we find one that doesn't produce a validation error
# XXX this does not yet support unions that include `tuple`, `list` or `Color`
I'm wondering if there's a better way to handle these types that want a listy thing as the only argument in their constructor.
Edited by Kaspar Emanuel