diff mbox series

[12/14] qapi/doc.py: Assert tag member is Enum type

Message ID 20200922211802.4083666-13-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt3 | expand

Commit Message

John Snow Sept. 22, 2020, 9:18 p.m. UTC
The type system can't quite express this constraint natively: members
can envelop any type -- but tag_members may only ever envelop an
enumerated type.

For now, shrug and add an assertion.

Note: These assertions don't appear to be useful yet because schema.py
is not yet typed. Once it is, these assertions will matter.

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

Comments

Eduardo Habkost Sept. 23, 2020, 9:07 p.m. UTC | #1
On Tue, Sep 22, 2020 at 05:18:00PM -0400, John Snow wrote:
> The type system can't quite express this constraint natively: members
> can envelop any type -- but tag_members may only ever envelop an
> enumerated type.
> 
> For now, shrug and add an assertion.
> 
> Note: These assertions don't appear to be useful yet because schema.py
> is not yet typed. Once it is, these assertions will matter.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
diff mbox series

Patch

diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index 2914e93b1c..b96d9046d3 100644
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -13,6 +13,7 @@ 
     QAPISchema,
     QAPISchemaEntity,
     QAPISchemaEnumMember,
+    QAPISchemaEnumType,
     QAPISchemaFeature,
     QAPISchemaMember,
     QAPISchemaObjectType,
@@ -193,6 +194,7 @@  def texi_members(doc: QAPIDoc,
             desc = texi_format(section.text)
         elif variants and variants.tag_member == section.member:
             assert isinstance(section.member, QAPISchemaObjectTypeMember)
+            assert isinstance(section.member.type, QAPISchemaEnumType)
             if not section.member.type.doc_type():
                 values = section.member.type.member_names()
                 members_text = ', '.join(['@t{"%s"}' % v for v in values])