def validation_enabled(is_validate=True): """ Context manager that is useful when temporarily enabling/disabling validation checks. :param bool is_validate: (optional; defaults to True) temporary validation check override. """ infer_validation_status = infer.is_validation_enabled() distribution_validation_status = dist.is_validation_enabled() try: enable_validation(is_validate) yield finally: dist.enable_validation(distribution_validation_status) infer.enable_validation(infer_validation_status)