Disclaimer: I'm a super noob in Python so please be patient.
I'm not even sure if this is possible at all, but we are using Schematics for data validation in Python and we have a list of dictionaries that can have values of multiple types (e.g. List of strings, List of numbers, List of Dictionaries etc.) So my first attempt was to use Union Type.
Now, the model looks like this:
class Filter(Model):
_id = ObjectIdType(default=ObjectId)
name = StringType()
filters = ListType(DictType(UnionType([ListType(StringType()),
ListType(NumberType()),BooleanType(), StringType()])))
created_at = DateTimeType(default=datetime.datetime.now)
updated_at = DateTimeType(default=datetime.datetime.now)
But for some unknown reason, isinstance() is giving me the error that arg 2 must be a type or tuple of types (which I have a feeling means that only 2 types can be unified). So I'm a bit out of ideas. I tried to write a custom model and use ModelType, but that didn't fly too far either.
Thank you in advance!