code: def test_custom_objective_safety():
      nrows = 100
      X = np.random.randn(nrows, 5)
      y_binary = np.arange(nrows) % 2
      classes = [0, 1, 2]
      nclass = len(classes)
      y_multiclass = np.arange(nrows) % nclass
      ds_binary = lgb.Dataset(X, y_binary).construct()
      ds_multiclass = lgb.Dataset(X, y_multiclass).construct()
      bad_bst_binary = lgb.Booster({"objective": "none"}, ds_binary)
      good_bst_binary = lgb.Booster({"objective": "none"}, ds_binary)
      bad_bst_multi = lgb.Booster(
          {"objective": "none", "num_class": nclass}, ds_multiclass
      )
      good_bst_multi = lgb.Booster(
          {"objective": "none", "num_class": nclass}, ds_multiclass
      )
      good_bst_binary.update(fobj=_good_gradients)
      with pytest.raises(
          ValueError,
          match=re.escape("number of models per one iteration (1)"),
      ):
          bad_bst_binary.update(fobj=_bad_gradients)
      good_bst_multi.update(fobj=_good_gradients)
      with pytest.raises(
          ValueError,
          match=re.escape(
              f"number of models per one iteration ({nclass})"
          ),
      ):
          bad_bst_multi.update(fobj=_bad_gradients)
  
imports: import filecmp
  import numbers
  import re
  from copy import deepcopy
  from os import getenv
  from pathlib import Path
  import numpy
  import pytest
  from scipy import sparse
  from sklearn.datasets import dump_svmlight_file, load_svmlight_file
  from sklearn.model_selection import train_test_split
  import lightgbm
  from lightgbm.compat import PANDAS_INSTALLED, pd_DataFrame, pd_Series
  from .utils import dummy_obj, load_breast_cancer, mse_obj, np_assert_array_equal
label_desc: Use image node_id 28 for calling a global function with example usage: test_custom_objective_safety() without return types