code: def dispatch_event(self, event: "Event") -> None:
          
          # Set the target of the event if it doesn't have one already. It could happen that
          # we are simply redispatching an event.
          if event.target is None:
              event.set_target(self)
  
          listeners: dict[types.MethodType, bool] = self._registered_listeners.get(event.type)
          if listeners is None:
              return
  
          for listener in listeners:
              listener(event)
docs: Dispatches the given event.
  
          It is the duty of this method to set the target of the dispatched event by calling
          `event.set_target(self)`.
  
          Args:
              event (Event): The event to dispatch. Must not be `None`.
  
          Raises:
              TypeError: If the event is `None` or its type is incorrect.