def METHOD_NAME(
    self,
    x: "torch.Tensor",
    y: Optional[Union["torch.Tensor", List[Dict[str, "torch.Tensor"]]]] = None,
) -> Tuple["torch.Tensor", Optional[Union["torch.Tensor", List[Dict[str, "torch.Tensor"]]]]]:
    """
    Square pad `x` and adjust bounding boxes for labels `y` accordingly.
    :param x: Input samples. A list of samples is also supported.
    :param y: Label of the samples `x`.
    :return: Transformed samples and labels.
    """
    import torch
    x_preprocess = []
    y_preprocess: Optional[Union[torch.Tensor, List[Dict[str, torch.Tensor]]]]
    if y is not None and self.label_type == "object_detection":
        y_preprocess = []
    else:
        y_preprocess = y
    for i, x_i in enumerate(tqdm(x, desc="ImageSquarePadPyTorch", disable=not self.verbose)):
        if not self.channels_first:
            x_i = torch.permute(x_i, (2, 0, 1))
        # Calculate padding
        _, height, width = x_i.shape
        if height > width:
            pad_left = int(np.floor((height - width) / 2))
            pad_right = int(np.ceil((height - width) / 2))
            pad_top = 0
            pad_bottom = 0
        else:
            pad_left = 0
            pad_right = 0
            pad_top = int(np.floor((width - height) / 2))
            pad_bottom = int(np.ceil((width - height) / 2))
        # Pad image to square size
        padding = [pad_left, pad_right, pad_top, pad_bottom]
        x_pad = torch.nn.functional.pad(x_i, padding, mode=self.pad_mode, **self.pad_kwargs)
        if not self.channels_first:
            x_pad = torch.permute(x_pad, (1, 2, 0))
        if self.clip_values is not None:
            x_pad = torch.clamp(x_pad, self.clip_values[0], self.clip_values[1])  # type: ignore
        x_preprocess.append(x_pad)
        if self.label_type == "object_detection" and y is not None:
            y_pad: Dict[str, torch.Tensor] = {}
            # Copy labels and ensure types
            if isinstance(y, list) and isinstance(y_preprocess, list):
                y_i = y[i]
                if isinstance(y_i, dict):
                    y_pad = {k: torch.clone(v) for k, v in y_i.items()}
                else:
                    raise TypeError("Wrong type for `y` and label_type=object_detection.")
            else:
                raise TypeError("Wrong type for `y` and label_type=object_detection.")
            # Shift bounding boxes
            y_pad["boxes"][:, 0] += pad_left
            y_pad["boxes"][:, 1] += pad_top
            y_pad["boxes"][:, 2] += pad_left
            y_pad["boxes"][:, 3] += pad_top
            y_preprocess.append(y_pad)
    if isinstance(x, torch.Tensor):
        return torch.stack(x_preprocess, dim=0), y_preprocess
    return x_preprocess, y_preprocess