def with_default(self, value: Union[Any, Callable[[MutableMapping[str, Any]], Any]], supplies_type: Type = None) -> "QueryValidator":
if self._current is None or self._current.child is not None:
raise QueryValidatorStructureError("No key is selected! Try using \"can_have\" before \"with_default\".")
if self._current.required:
raise QueryValidatorStructureError("Can't assign a default value to a required key! Try using \"can_have\" instead of \"have\".")
if supplies_type:
expected_type = supplies_type
else:
expected_type = type(value)
default_node = _DefaultValueNode(self._current.key, value, supplies_type)
result = self.as_(expected_type)
result._current.child.child = default_node
return result
评论列表
文章目录