info.types could be a tuple like (str, ContainerTypeInfo()). That means
we have to check types one by one and only print error if none of them
matched.
Also fix the case when default value is None for a container type, it
should leave the value to None to be able to distinguish between unset
and empty list.
pull/9382/head
Xavier Claessens3 years agocommitted byXavier Claessens
# set the value to the default, this ensuring all kwargs are present
# This both simplifies the typing checking and the usage
# Create a shallow copy of the container (and do a type
# conversion if necessary). This allows mutable types to
# be used safely as default values
ifisinstance(info.types,ContainerTypeInfo):
assertisinstance(info.default,info.types.container),f'In function {name} default value of {info.name} is not a valid type, got {type(info.default)}, expected {info.types.container}[{info.types.contains}]'
foritemininfo.default:
assertisinstance(item,info.types.contains),f'In function {name} default value of {info.name}, container has invalid value of {item}, which is of type {type(item)}, but should be {info.types.contains}'
assertisinstance(info.default,info.types),f'In funcion {name} default value of {info.name} is not a valid type, got {type(info.default)} expected {info.types}'
kwargs[info.name]=info.default
assertcheck_value_type(info.default),f'In funcion {name} default value of {info.name} is not a valid type, got {type(info.default)} expected {types_description()}'
# Create a shallow copy of the container. This allows mutable