# Buggy code
def _parse_fill(fill, img, min_pil_version):
    """Helper function to get the fill color for rotate and perspective transforms.

    Args:
        fill (n-tuple or int or float): Pixel fill value for area outside the transformed
            image. If int or float, the value is used for all bands respectively.
            Defaults to 0 for all bands.
        img (PIL Image): Image to be filled.
        min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
            was first introduced in the calling function. (e.g. rotate->5.2.0, perspective->5.0.0)

    Returns:
        dict: kwarg for ``fillcolor``
    """
    major_found, minor_found = (int(v) for v in PILLOW_VERSION.split(".")[:2])
    major_required, minor_required = (int(v) for v in min_pil_version.split(".")[:2])
    if major_found < major_required or (
        major_found == major_required and minor_found < minor_required
    ):
        if fill is None:
            return {}
        else:
            msg = (
                "The option to fill background area of the transformed image, "
                "requires pillow>={}"
            )
            raise RuntimeError(msg.format(min_pil_version))

    num_bands = len(img.getbands())
    if fill is None:
        fill = 0
    if isinstance(fill, (int, float)) and num_bands > 1:
        fill = tuple([fill] * num_bands)
    if not isinstance(fill, (int, float)) and len(fill) != num_bands:
        msg = (
            "The number of elements in 'fill' does not match the number of "
            "bands of the image ({} != {})"
        )
        raise ValueError(msg.format(len(fill), num_bands))

    return {"fillcolor": fill}


# Traceback (TypeError)
TypeError                                 Traceback (most recent call last)
<ipython-input-28-086b6b55847c> in <module>
4 x = PIL.Image.fromarray(t.numpy())
5 f = torchvision.transforms.Pad(2)
----> 6 f(x)

~/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py in __call__(self, img)
338             PIL Image: Padded image.
339         """
--> 340         return F.pad(img, self.padding, self.fill, self.padding_mode)
341
342     def __repr__(self):

~/anaconda3/lib/python3.7/site-packages/torchvision/transforms/functional.py in pad(img, padding, fill, padding_mode)
405             return image
406
--> 407         return ImageOps.expand(img, border=padding, fill=fill)
408     else:
409         if isinstance(padding, int):

~/anaconda3/lib/python3.7/site-packages/PIL/ImageOps.py in expand(image, border, fill)
360     width = left + image.size[0] + right
361     height = top + image.size[1] + bottom
--> 362     out = Image.new(image.mode, (width, height), _color(fill, image.mode))
363     out.paste(image, (left, top))
364     return out

~/anaconda3/lib/python3.7/site-packages/PIL/Image.py in new(mode, size, color)
2611         im.palette = ImagePalette.ImagePalette()
2612         color = im.palette.getcolor(color)
-> 2613     return im._new(core.fill(mode, size, color))

# Fixed code
def _parse_fill(fill, img, min_pil_version, name="fillcolor"):
    """Helper function to get the fill color for rotate, perspective transforms, and pad.

    Args:
        fill (n-tuple or int or float): Pixel fill value for area outside the transformed
            image. If int or float, the value is used for all bands respectively.
            Defaults to 0 for all bands.
        img (PIL Image): Image to be filled.
        min_pil_version (str): The minimum PILLOW version for when the ``fillcolor`` option
            was first introduced in the calling function. (e.g. rotate->5.2.0, perspective->5.0.0)
        name (str): Name of the ``fillcolor`` option in the output. Defaults to ``"fillcolor"``.

    Returns:
        dict: kwarg for ``fillcolor``
    """
    major_found, minor_found = (int(v) for v in PILLOW_VERSION.split(".")[:2])
    major_required, minor_required = (int(v) for v in min_pil_version.split(".")[:2])
    if major_found < major_required or (
        major_found == major_required and minor_found < minor_required
    ):
        if fill is None:
            return {}
        else:
            msg = (
                "The option to fill background area of the transformed image, "
                "requires pillow>={}"
            )
            raise RuntimeError(msg.format(min_pil_version))

    num_bands = len(img.getbands())
    if fill is None:
        fill = 0
    if isinstance(fill, (int, float)) and num_bands > 1:
        fill = tuple([fill] * num_bands)
    if not isinstance(fill, (int, float)) and len(fill) != num_bands:
        msg = (
            "The number of elements in 'fill' does not match the number of "
            "bands of the image ({} != {})"
        )
        raise ValueError(msg.format(len(fill), num_bands))

    return {name: fill}