code: def test_custom_batch_sampler_no_sampler():
      """Tests whether appropriate error is raised when the custom `BatchSampler` does not support sampler argument."""
  
      class MyBatchSampler(BatchSampler):
          # Custom batch sampler, without sampler argument.
          def __init__(self, extra_arg):
              self.extra_arg = extra_arg
              super().__init__(RandomSampler(range(10)), 10, False)
  
      with _replace_dunder_methods(BatchSampler):
          # instantiate within `_replace_dunder_method` context manager, simulating `*_dataloader` hooks
          batch_sampler = MyBatchSampler("random_str")
      dataloader = DataLoader(range(10), batch_sampler=batch_sampler)
  
      # assert that passed information got saved
      assert dataloader.batch_sampler.__pl_saved_args == ("random_str",)
      assert dataloader.batch_sampler.__pl_saved_kwargs == {}
      assert dataloader.batch_sampler.__pl_saved_arg_names == (
          "extra_arg",
      )
      assert dataloader.batch_sampler.__pl_saved_default_kwargs == {}
  
      # Assert that error is raised
      with pytest.raises(
          TypeError, match="sampler into the batch sampler"
      ):
          _ = _update_dataloader(dataloader, dataloader.sampler)
  
imports: import contextlib
  import os
  import random
  from unittest import mock
  from unittest.mock import Mock
  import lightning.fabric
  import numpy
  import pytest
  import torch
  from lightning.fabric.utilities.data import AttributeDict, _get_dataloader_init_args_and_kwargs, _replace_dunder_methods, _replace_value_in_saved_args, _set_sampler_epoch, _update_dataloader, _WrapAttrTag, has_iterable_dataset, has_len, suggested_max_num_workers
  from lightning.fabric.utilities.exceptions import MisconfigurationException
  from lightning_utilities.test.warning import no_warning_call
  from torch import Tensor
  from torch.utils.data import BatchSampler, DataLoader, RandomSampler
  from tests_fabric.helpers.models import RandomDataset, RandomIterableDataset
label_desc: Use image node_id 13 for calling a global function with example usage: test_custom_batch_sampler_no_sampler() without return types