base_validator.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:tripoli 作者: DDMAL 项目源码 文件源码
def mute_errors(self, fn, *args, **kwargs):
        """Run given function and catch any of the errors it logged.

        The self._errors key will not be changed by using this function.

        Works by patching the BaseValidator.log_error function.
        BaseValidator.log_error should not be overridden in children.
        """
        caught_errors = set()

        def patched_log_error(self, field, msg):
            tb = traceback.extract_stack()[:-1] if self.debug else None
            caught_errors.add(ValidatorLogError(msg, self._path + (field,), tb))

        old_log_error = BaseValidator.log_error
        try:
            BaseValidator.log_error = patched_log_error
            val = fn(*args, **kwargs)
        finally:
            BaseValidator.log_error = old_log_error
        return val, caught_errors
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号