code: def test_custom_batch_sampler():
      """Test that a custom (non-PyTorch) batch sampler requires the user to set `use_distributed_sampler=False`."""
  
      class CustomBatchSampler:  # not inheriting from `BatchSampler`
          def __iter__(self):
              while True:
                  yield [0, 1, 2, 3]
  
      batch_sampler = CustomBatchSampler()
      dataloader = DataLoader(range(100), batch_sampler=batch_sampler)
      with pytest.raises(
          TypeError,
          match=r"can't inject a \(distributed\) sampler into your batch sampler",
      ):
          _ = _update_dataloader(dataloader, sampler=Mock())
  
imports: from dataclasses import dataclass
  from unittest.mock import Mock
  import numpy
  import pytest
  import torch
  from lightning.fabric.utilities.data import _replace_dunder_methods
  from lightning.pytorch import Trainer
  from lightning.pytorch.demos.boring_classes import RandomDataset, RandomIterableDataset
  from lightning.pytorch.overrides.distributed import _IndexBatchSamplerWrapper
  from lightning.pytorch.trainer.states import RunningStage
  from lightning.pytorch.utilities.data import _get_dataloader_init_args_and_kwargs, _update_dataloader, extract_batch_size, has_len_all_ranks, warning_cache
  from lightning.pytorch.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
label_desc: Use image node_id 6 for calling a global function with example usage: test_custom_batch_sampler() without return types