]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
python: backport 'EventListener: add __repr__ method'
authorJohn Snow <jsnow@redhat.com>
Fri, 22 Jul 2022 19:42:23 +0000 (15:42 -0400)
committerJohn Snow <jsnow@redhat.com>
Mon, 15 Sep 2025 18:36:01 +0000 (14:36 -0400)
When the object is not stateful, this repr method prints what you'd
expect. In cases where there are pending events, the output is augmented
to illustrate that.

The object itself has no idea if it's "active" or not, so it cannot
convey that information.

Signed-off-by: John Snow <jsnow@redhat.com>
cherry picked from commit python-qemu-qmp@8a6f2e136dae395fec8aa5fd77487cfe12d9e05e
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
python/qemu/qmp/events.py

index 6199776cc6647fe12cee54d371972ea89437e9db..66583496192794da4900d1a10055579f647aba36 100644 (file)
@@ -497,6 +497,21 @@ class EventListener:
         #: Optional, secondary event filter.
         self.event_filter: Optional[EventFilter] = event_filter
 
+    def __repr__(self) -> str:
+        args: List[str] = []
+        if self.names:
+            args.append(f"names={self.names!r}")
+        if self.event_filter:
+            args.append(f"event_filter={self.event_filter!r}")
+
+        if self._queue.qsize():
+            state = f"<pending={self._queue.qsize()}>"
+        else:
+            state = ''
+
+        argstr = ", ".join(args)
+        return f"{type(self).__name__}{state}({argstr})"
+
     @property
     def history(self) -> Tuple[Message, ...]:
         """