[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 34/36] qapi/visit.py: assert tag_member contains a QAPISchemaE
From: |
John Snow |
Subject: |
[PATCH v6 34/36] qapi/visit.py: assert tag_member contains a QAPISchemaEnumType |
Date: |
Fri, 9 Oct 2020 12:15:56 -0400 |
This is true by design, but not presently able to be expressed in the
type system. An assertion helps mypy understand our constraints.
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cleber Rosa <crosa@redhat.com>
---
scripts/qapi/visit.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 708f72c4a1e..e00f2a09d75 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -22,7 +22,7 @@
mcgen,
)
from .gen import QAPISchemaModularCVisitor, ifcontext
-from .schema import QAPISchemaObjectType
+from .schema import QAPISchemaEnumType, QAPISchemaObjectType
def gen_visit_decl(name, scalar=False):
@@ -84,15 +84,17 @@ def gen_visit_object_members(name, base, members, variants):
ret += gen_endif(memb.ifcond)
if variants:
+ tag_member = variants.tag_member
+ assert isinstance(tag_member.type, QAPISchemaEnumType)
+
ret += mcgen('''
switch (obj->%(c_name)s) {
''',
- c_name=c_name(variants.tag_member.name))
+ c_name=c_name(tag_member.name))
for var in variants.variants:
- case_str = c_enum_const(variants.tag_member.type.name,
- var.name,
- variants.tag_member.type.prefix)
+ case_str = c_enum_const(tag_member.type.name, var.name,
+ tag_member.type.prefix)
ret += gen_if(var.ifcond)
if var.type.name == 'q_empty':
# valid variant and nothing to do
--
2.26.2
- Re: [PATCH v6 26/36] qapi/gen.py: Fix edge-case of _is_user_module, (continued)
- [PATCH v6 22/36] qapi/commands.py: add type hint annotations, John Snow, 2020/10/09
- [PATCH v6 25/36] qapi/source.py: delint with pylint, John Snow, 2020/10/09
- [PATCH v6 21/36] qapi/commands.py: Don't re-bind to variable of different type, John Snow, 2020/10/09
- [PATCH v6 28/36] qapi/gen.py: Enable checking with mypy, John Snow, 2020/10/09
- [PATCH v6 27/36] qapi/gen.py: add type hint annotations, John Snow, 2020/10/09
- [PATCH v6 30/36] qapi/gen.py: update write() to be more idiomatic, John Snow, 2020/10/09
- [PATCH v6 33/36] qapi/types.py: remove one-letter variables, John Snow, 2020/10/09
- [PATCH v6 29/36] qapi/gen.py: Remove unused parameter, John Snow, 2020/10/09
- [PATCH v6 35/36] qapi/visit.py: remove unused parameters from gen_visit_object, John Snow, 2020/10/09
- [PATCH v6 34/36] qapi/visit.py: assert tag_member contains a QAPISchemaEnumType,
John Snow <=
- [PATCH v6 32/36] qapi/types.py: add type hint annotations, John Snow, 2020/10/09
- [PATCH v6 36/36] qapi/visit.py: add type hint annotations, John Snow, 2020/10/09
- [PATCH v6 31/36] qapi/gen.py: delint with pylint, John Snow, 2020/10/09
- Re: [PATCH v6 00/36] qapi: static typing conversion, pt1, Markus Armbruster, 2020/10/10