'Expand any dynamic values to their correct types / values.'

def __expand_dynamic_values(self, name, value):

    if (not isinstance(value, (dict, list, tuple))):
        return value
    is_dict = isinstance(value, dict)
    if (is_dict and ('_cls' in value)):
        cls = get_document(value['_cls'])
        return cls(**value)
    if is_dict:
        value = {k: self.__expand_dynamic_values(k, v) for (k, v) in value.items()}
    else:
        value = [self.__expand_dynamic_values(name, v) for v in value]
    EmbeddedDocumentListField = _import_class('EmbeddedDocumentListField')
    if (isinstance(value, (list, tuple)) and (not isinstance(value, BaseList))):
        if issubclass(type(self), EmbeddedDocumentListField):
            value = EmbeddedDocumentList(value, self, name)
        else:
            value = BaseList(value, self, name)
    elif (isinstance(value, dict) and (not isinstance(value, BaseDict))):
        value = BaseDict(value, self, name)
    return value
