[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 06/22] qapi/parser: assert get_expr returns object in outer loop
From: |
John Snow |
Subject: |
[PATCH 06/22] qapi/parser: assert get_expr returns object in outer loop |
Date: |
Wed, 21 Apr 2021 23:07:04 -0400 |
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 <jsnow@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
- Re: [PATCH 03/22] qapi/source: Remove line number from QAPISourceInfo initializer, (continued)
[PATCH 01/22] qapi/parser: Don't try to handle file errors, John Snow, 2021/04/21
[PATCH 04/22] qapi/parser: factor parsing routine into method, John Snow, 2021/04/21
[PATCH 08/22] qapi/parser: Use @staticmethod where appropriate, John Snow, 2021/04/21
[PATCH 06/22] qapi/parser: assert get_expr returns object in outer loop,
John Snow <=
[PATCH 09/22] qapi: add match_nofail helper, John Snow, 2021/04/21
[PATCH 05/22] qapi/parser: Assert lexer value is a string, John Snow, 2021/04/21