#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2025/3/15 21:23 # @Author : AngesZhu # @File : if_null_rules.py # @Desc : 校验字段是否为空 from typing import Any from utils.validation_error_utils import handle_validation_errors, EmptyFieldError def validate_not_empty(value: Any, field: str) -> bool: """ 校验字段是否为空 :param value: 字段值 :param field: 字段名称 :return: 是否通过校验 :raises EmptyFieldError: 如果字段为空 """ with handle_validation_errors(field, {"value": value}): if value is None or (isinstance(value, str) and not value.strip()): raise EmptyFieldError(f"字段 '{field}' 不能为空", field) return True