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

Code before:
        """Update the canvas cursor."""
        self.ax.get_figure(root=True).canvas.set_cursor(cursor)

    def _save_blit_background(self, background):
        """
        Save a blit background.

        The background is stored on the canvas in a uniquely identifiable way.
        It should be read back via `._load_blit_background`. Be prepared that
        some events may invalidate the background, in which case
        `._load_blit_background` will return None.

        This currently allows at most one background per widget, which is
        good enough for all existing widgets.
        """
        if self._blit_background_id is None:
            self._blit_background_id = self.canvas._get_blit_background_id()
        self.canvas._blit_backgrounds[self._blit_background_id] = background

    def _load_blit_background(self):
        """Load a blit background; may be None at any time."""
        return self.canvas._blit_backgrounds.get(self._blit_background_id)


class Button(AxesWidget):
    """
    A GUI neutral button.

    For the button to remain responsive you must keep a reference to it.
    Call `.on_clicked` to connect to the button.

    Attributes
    ----------
    ax
        The `~.axes.Axes` the button renders into.
    label
        A `.Text` instance.
    color
        The color of the button when not hovering.
    hovercolor
        The color of the button when hovering.
    """

    def __init__(self, ax, label, image=None,
                 color='0.85', hovercolor='0.95', *, useblit=True):
        """
        Parameters
        ----------
        ax : `~matplotlib.axes.Axes`
            The `~.axes.Axes` instance the button will be placed into.
        label : str

Review comment (suggestion):
I am not sure that this is enough to guarantee a valid background because of you could have change the size or dpi of the canvas.

On the other hand, this is _already_ true with the way we do it so this is not making it worse. 

Code after:
        # docstring inherited
        return super().ignore(event) or self.canvas is None

    def _set_cursor(self, cursor):
        """Update the canvas cursor."""
        self.ax.get_figure(root=True).canvas.set_cursor(cursor)

    def _save_blit_background(self, background):
        """
        Save a blit background.

        The background is stored on the canvas in a uniquely identifiable way.
        It should be read back via `._load_blit_background`. Be prepared that
        some events may invalidate the background, in which case
        `._load_blit_background` will return None.

        This currently allows at most one background per widget, which is
        good enough for all existing widgets.
        """
        if self._blit_background_id is None:
            self._blit_background_id = self.canvas._get_blit_background_id()
        self.canvas._blit_backgrounds[self._blit_background_id] = background

    def _load_blit_background(self):
        """Load a blit background; may be None at any time."""
        return self.canvas._blit_backgrounds.get(self._blit_background_id)


class Button(AxesWidget):
    """
    A GUI neutral button.

    For the button to remain responsive you must keep a reference to it.
    Call `.on_clicked` to connect to the button.

    Attributes
    ----------
    ax
        The `~.axes.Axes` the button renders into.
    label
        A `.Text` instance.
    color
        The color of the button when not hovering.
    hovercolor
        The color of the button when hovering.
    """

    def __init__(self, ax, label, image=None,
                 color='0.85', hovercolor='0.95', *, useblit=True):
        """
        Parameters