All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
	John Snow <jsnow@redhat.com>,
	"Niteesh G . S ." <niteesh.gs@gmail.com>,
	Eduardo Habkost <ehabkost@redhat.com>,
	Cleber Rosa <crosa@redhat.com>
Subject: [PATCH 07/11] python/qmp: Correct type of QMPReturnValue
Date: Fri,  4 Jun 2021 11:55:28 -0400	[thread overview]
Message-ID: <20210604155532.1499282-8-jsnow@redhat.com> (raw)
In-Reply-To: <20210604155532.1499282-1-jsnow@redhat.com>

It's only a Dict[str, Any] most of the time. It's not actually
guaranteed to be anything in particular. Fix this type to be
more accurate to the reality we live in.

Signed-off-by: John Snow <jsnow@redhat.com>

---

A note for Vladimir: I'm not using 'object' here yet because it causes a
few regressions in iotests.py type checking that I'm not ready to fix
just yet, but it will eventually happen.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 python/qemu/qmp/__init__.py | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/python/qemu/qmp/__init__.py b/python/qemu/qmp/__init__.py
index 822c793c32..a6e1a7b857 100644
--- a/python/qemu/qmp/__init__.py
+++ b/python/qemu/qmp/__init__.py
@@ -35,14 +35,19 @@
 )
 
 
-# QMPMessage is a QMP Message of any kind.
-# e.g. {'yee': 'haw'}
-#
-# QMPReturnValue is the inner value of return values only.
-# {'return': {}} is the QMPMessage,
-# {} is the QMPReturnValue.
+#: QMPMessage is an entire QMP message of any kind.
 QMPMessage = Dict[str, Any]
-QMPReturnValue = Dict[str, Any]
+
+#: QMPReturnValue is the 'return' value of a command.
+QMPReturnValue = object
+
+# QMPMessage can be outgoing commands or incoming events/returns.
+# QMPReturnValue is usually a dict/json object, but due to QAPI's
+# 'returns-whitelist', it can actually be anything.
+#
+# {'return': {}} is a QMPMessage,
+# {} is the QMPReturnValue.
+
 
 InternetAddrT = Tuple[str, int]
 UnixAddrT = str
@@ -297,8 +302,8 @@ def cmd_obj(self, qmp_cmd: QMPMessage) -> QMPMessage:
         return resp
 
     def cmd(self, name: str,
-            args: Optional[Dict[str, Any]] = None,
-            cmd_id: Optional[Any] = None) -> QMPMessage:
+            args: Optional[Dict[str, object]] = None,
+            cmd_id: Optional[object] = None) -> QMPMessage:
         """
         Build a QMP command and send it to the QMP Monitor.
 
@@ -313,7 +318,7 @@ def cmd(self, name: str,
             qmp_cmd['id'] = cmd_id
         return self.cmd_obj(qmp_cmd)
 
-    def command(self, cmd: str, **kwds: Any) -> QMPReturnValue:
+    def command(self, cmd: str, **kwds: object) -> QMPReturnValue:
         """
         Build and send a QMP command to the monitor, report errors if any
         """
-- 
2.31.1



  parent reply	other threads:[~2021-06-04 16:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 15:55 [PATCH 00/11] python: move /scripts/qmp/gemu-ga-client.py to qemu.qmp package John Snow
2021-06-04 15:55 ` [PATCH 01/11] scripts/qemu-ga-client: apply isort rules John Snow
2021-06-04 15:55 ` [PATCH 02/11] scripts/qemu-ga-client: apply (most) flake8 rules John Snow
2021-06-04 15:55 ` [PATCH 03/11] scripts/qemu-ga-client: Fix exception handling John Snow
2021-06-04 15:55 ` [PATCH 04/11] scripts/qemu-ga-client: replace deprecated optparse with argparse John Snow
2021-06-04 15:55 ` [PATCH 05/11] scripts/qemu-ga-client: add module docstring John Snow
2021-06-04 15:55 ` [PATCH 06/11] scripts/qemu-ga-client: apply (most) pylint rules John Snow
2021-06-04 15:55 ` John Snow [this message]
2021-06-04 15:55 ` [PATCH 08/11] scripts/qemu-ga-client: add mypy type hints John Snow
2021-06-04 15:55 ` [PATCH 09/11] scripts/qemu-ga-client: move to python/qemu/qmp/qemu_ga_client.py John Snow
2021-06-04 15:55 ` [PATCH 10/11] python/qemu-ga-client: add entry point John Snow
2021-06-04 15:55 ` [PATCH 11/11] scripts/qemu-ga-client: Add forwarder shim John Snow
2021-06-11 20:58 ` [PATCH 00/11] python: move /scripts/qmp/gemu-ga-client.py to qemu.qmp package John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210604155532.1499282-8-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=niteesh.gs@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.