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

Code before:
            name, canvas, x, y, guiEvent=guiEvent, modifiers=modifiers)
        if button in MouseButton.__members__.values():
            button = MouseButton(button)
        if name == "scroll_event" and button is None:
            if step > 0:
                button = "up"
            elif step < 0:
                button = "down"
        self.button = button
        if name == "motion_notify_event":
            self.buttons = frozenset(buttons if buttons is not None else [])
        else:
            # We don't support 'buttons' for button_press/release_event because
            # toolkits are inconsistent as to whether they report the state
            # before or after the event.
            if buttons:
                raise ValueError(
                    "'buttons' is only supported for 'motion_notify_event'")
            self.buttons = None
        self.key = key
        self.step = step
        self.dblclick = dblclick

    @classmethod
    def _from_ax_coords(cls, name, ax, xy, *args, **kwargs):
        """Generate a synthetic event at a given axes coordinate."""
        x, y = ax.transData.transform(xy)
        event = cls(name, ax.figure.canvas, x, y, *args, **kwargs)
        event.inaxes = ax
        event.xdata, event.ydata = xy  # Force exact xy to avoid fp roundtrip issues.
        return event

    def __str__(self):
        return (f"{self.name}: "
                f"xy=({self.x}, {self.y}) xydata=({self.xdata}, {self.ydata}) "
                f"button={self.button} dblclick={self.dblclick} "
                f"inaxes={self.inaxes}")


class PickEvent(Event):
    """
    A pick event.

    This event is fired when the user picks a location on the canvas
    sufficiently close to an artist that has been made pickable with
    `.Artist.set_picker`.

    A PickEvent has a number of special attributes in addition to those defined
    by the parent `Event` class.

    Attributes

Review comment (suggestion):
```suggestion
        """
        Generate a synthetic event at a given axes coordinate.

        This is mainly intended for creating events during testing. The event can be send
        by calling its ``_process()`` method.
        
        args and kwargs are mapped to MouseEvent.__init__ parameters, starting with
        `button`.
        """
```

Code after:
            name, canvas, x, y, guiEvent=guiEvent, modifiers=modifiers)
        if button in MouseButton.__members__.values():
            button = MouseButton(button)
        if name == "scroll_event" and button is None:
            if step > 0:
                button = "up"
            elif step < 0:
                button = "down"
        self.button = button
        if name == "motion_notify_event":
            self.buttons = frozenset(buttons if buttons is not None else [])
        else:
            # We don't support 'buttons' for button_press/release_event because
            # toolkits are inconsistent as to whether they report the state
            # before or after the event.
            if buttons:
                raise ValueError(
                    "'buttons' is only supported for 'motion_notify_event'")
            self.buttons = None
        self.key = key
        self.step = step
        self.dblclick = dblclick

    @classmethod
    def _from_ax_coords(cls, name, ax, xy, *args, **kwargs):
        """
        Generate a synthetic event at a given axes coordinate.

        This method is intended for creating events during testing.  The event
        can be emitted by calling its ``_process()`` method.

        args and kwargs are mapped to `.MouseEvent.__init__` parameters,
        starting with `button`.
        """
        x, y = ax.transData.transform(xy)
        event = cls(name, ax.figure.canvas, x, y, *args, **kwargs)
        event.inaxes = ax
        event.xdata, event.ydata = xy  # Force exact xy to avoid fp roundtrip issues.
        return event

    def __str__(self):
        return (f"{self.name}: "
                f"xy=({self.x}, {self.y}) xydata=({self.xdata}, {self.ydata}) "
                f"button={self.button} dblclick={self.dblclick} "
                f"inaxes={self.inaxes}")


class PickEvent(Event):
    """
    A pick event.