Repository: matplotlib/matplotlib
File: lib/matplotlib/colors.py (Python)

Code before:
        # if isinstance(Image, lut):
        #    lut = image.pil_to_array(lut)
        lut = np.array(lut, copy=True)
        if lut.ndim != 3 or lut.shape[2] not in (3, 4):
            raise ValueError("The lut must be an array of shape (n, m, 3) or (n, m, 4)",
                             " or a PIL.image encoded as RGB or RGBA")

        if lut.dtype == np.uint8:
            lut = lut.astype(np.float32)/255
        if lut.shape[2] == 3:
            new_lut = np.empty((lut.shape[0], lut.shape[1], 4), dtype=lut.dtype)
            new_lut[:, :, :3] = lut
            new_lut[:, :, 3] = 1.
            lut = new_lut
        self._lut = lut
        super().__init__(lut.shape[0], lut.shape[1], shape, origin, name=name)

    def _init(self):
        self._isinit = True


class Norm(ABC):

    def __init__(self):
        """
        Abstract base class for normalizations.

        Subclasses include `Normalize` which maps from a scalar to
        a scalar. However, this class makes no such requirement, and subclasses may
        support the normalization of multiple variates simultaneously, with
        separate normalization for each variate.
        """
        self.callbacks = cbook.CallbackRegistry(signals=["changed"])

    @property
    @abstractmethod
    def vmin(self):
        """Lower limit of the input data interval; maps to 0."""
        pass

    @property
    @abstractmethod
    def vmax(self):
        """Upper limit of the input data interval; maps to 1."""
        pass

    @property
    @abstractmethod
    def clip(self):
        """
        Determines the behavior for mapping values outside the range ``[vmin, vmax]``.

Review comment (suggestion):
Docstring seems like it should be on the class, not the `__init__`.

Code after:
        # if isinstance(Image, lut):
        #    lut = image.pil_to_array(lut)
        lut = np.array(lut, copy=True)
        if lut.ndim != 3 or lut.shape[2] not in (3, 4):
            raise ValueError("The lut must be an array of shape (n, m, 3) or (n, m, 4)",
                             " or a PIL.image encoded as RGB or RGBA")

        if lut.dtype == np.uint8:
            lut = lut.astype(np.float32)/255
        if lut.shape[2] == 3:
            new_lut = np.empty((lut.shape[0], lut.shape[1], 4), dtype=lut.dtype)
            new_lut[:, :, :3] = lut
            new_lut[:, :, 3] = 1.
            lut = new_lut
        self._lut = lut
        super().__init__(lut.shape[0], lut.shape[1], shape, origin, name=name)

    def _init(self):
        self._isinit = True


class Norm(ABC):
    """
    Abstract base class for normalizations.

    Subclasses include `Normalize` which maps from a scalar to
    a scalar. However, this class makes no such requirement, and subclasses may
    support the normalization of multiple variates simultaneously, with
    separate normalization for each variate.
    """

    def __init__(self):
        self.callbacks = cbook.CallbackRegistry(signals=["changed"])

    @property
    @abstractmethod
    def vmin(self):
        """Lower limit of the input data interval; maps to 0."""
        pass

    @property
    @abstractmethod
    def vmax(self):
        """Upper limit of the input data interval; maps to 1."""
        pass

    @property
    @abstractmethod
    def clip(self):
        """
        Determines the behavior for mapping values outside the range ``[vmin, vmax]``.