qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 08/25] qapi/schema.py: Allow alternate_type to assert


From: John Snow
Subject: [PATCH 08/25] qapi/schema.py: Allow alternate_type to assert
Date: Tue, 22 Sep 2020 18:44:44 -0400

It is generally nicer to just let things fail, because it makes the
static type hints less infected with Optional[T], where a future
programmer using the library has to wonder what that means.

Let errors be errors.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/schema.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 15ff441660..a84d8549a4 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -199,7 +199,7 @@ def alternate_qtype(self):
             'boolean': 'QTYPE_QBOOL',
             'object':  'QTYPE_QDICT'
         }
-        return json2qtype.get(self.json_type())
+        return json2qtype[self.json_type()]
 
     def doc_type(self):
         if self.is_implicit():
@@ -480,8 +480,9 @@ def check(self, schema):
         types_seen = {}
         for v in self.variants.variants:
             v.check_clash(self.info, seen)
-            qtype = v.type.alternate_qtype()
-            if not qtype:
+            try:
+                qtype = v.type.alternate_qtype()
+            except KeyError:
                 raise QAPISemError(
                     self.info,
                     "%s cannot use %s"
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]