get_expr can return many things, depending on where it is used. In the
outer parsing loop, we expect and require it to return a dict.

(It's (maybe) a bit involved to teach mypy that when nested is False,
this is already always True. I'll look into it later, maybe.)

Signed-off-by: John Snow <js...@redhat.com>
---
 scripts/qapi/parser.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index c75434e75a5..6b443b1247e 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -78,6 +78,8 @@ def _parse(self):
                 continue
 
             expr = self.get_expr(False)
+            assert isinstance(expr, dict)  # Guaranteed when nested=False
+
             if 'include' in expr:
                 self.reject_expr_doc(cur_doc)
                 if len(expr) != 1:
@@ -278,6 +280,7 @@ def get_values(self):
             self.accept()
 
     def get_expr(self, nested):
+        # TODO: Teach mypy that nested=False means the retval is a Dict.
         if self.tok != '{' and not nested:
             raise QAPIParseError(self, "expected '{'")
         if self.tok == '{':
-- 
2.30.2


Reply via email to