code: def test_custom_batch_sampler_no_drop_last():
      """Tests whether appropriate warning is raised when the custom `BatchSampler` does not support `drop_last` and we
      want to reset it."""
  
      class MyBatchSampler(BatchSampler):
          # Custom batch sampler with extra argument, but without `drop_last`
          def __init__(self, sampler, extra_arg):
              self.extra_arg = extra_arg
              super().__init__(sampler, 10, False)
  
      sampler = RandomSampler(range(10))
      with _replace_dunder_methods(BatchSampler):
          # instantiate within `_replace_dunder_method` context manager, simulating `*_dataloader` hooks
          batch_sampler = MyBatchSampler(sampler, "random_str")
  
      dataloader = DataLoader(range(10), batch_sampler=batch_sampler)
  
      # assert that passed information got saved
      assert dataloader.batch_sampler.__pl_saved_args == (
          sampler,
          "random_str",
      )
      assert dataloader.batch_sampler.__pl_saved_kwargs == {}
      assert dataloader.batch_sampler.__pl_saved_arg_names == (
          "sampler",
          "extra_arg",
      )
      assert dataloader.batch_sampler.__pl_saved_default_kwargs == {}
  
      # Assert that warning is raised
      with pytest.warns(UserWarning, match="drop_last=False"):
          _ = _update_dataloader(
              dataloader,
              dataloader.sampler,
              mode=RunningStage.PREDICTING,
          )
  
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 7 for calling a global function with example usage: test_custom_batch_sampler_no_drop_last() without return types