diff mbox series

[03/14] qapi/doc.py: Add assertion on section.member

Message ID 20200922211802.4083666-4-jsnow@redhat.com (mailing list archive)
State New, archived
Headers show
Series qapi: static typing conversion, pt3 | expand

Commit Message

John Snow Sept. 22, 2020, 9:17 p.m. UTC
Similarly to other cases, we lack the power at the moment to express
that a specific member is constrained to a certain containing type. Add
an assertion before we use properties specific to that type.

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

Comments

Eduardo Habkost Sept. 23, 2020, 8:46 p.m. UTC | #1
On Tue, Sep 22, 2020 at 05:17:51PM -0400, John Snow wrote:
> Similarly to other cases, we lack the power at the moment to express
> that a specific member is constrained to a certain containing type. Add
> an assertion before we use properties specific to that type.
> 
> 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 66333629d6..c645876b24 100644
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -5,9 +5,10 @@ 
 """This script produces the documentation of a qapi schema in texinfo format"""
 
 import re
+from typing import Optional
+
 from .gen import QAPIGenDoc
-from .schema import QAPISchemaVisitor
-
+from .schema import QAPISchemaVisitor, QAPISchemaObjectTypeMember
 
 MSG_FMT = """
 @deftypefn {type} {{}} {name}
@@ -155,14 +156,17 @@  def texi_members(doc, what, base=None, variants=None,
     items = ''
     for section in doc.args.values():
         # TODO Drop fallbacks when undocumented members are outlawed
+        desc: Optional[str] = None
+
         if section.text:
             desc = texi_format(section.text)
-        elif (variants and variants.tag_member == section.member
-              and not section.member.type.doc_type()):
-            values = section.member.type.member_names()
-            members_text = ', '.join(['@t{"%s"}' % v for v in values])
-            desc = 'One of ' + members_text + '\n'
-        else:
+        elif variants and variants.tag_member == section.member:
+            assert isinstance(section.member, QAPISchemaObjectTypeMember)
+            if not section.member.type.doc_type():
+                values = section.member.type.member_names()
+                members_text = ', '.join(['@t{"%s"}' % v for v in values])
+                desc = 'One of ' + members_text + '\n'
+        if desc is None:
             desc = 'Not documented\n'
 
         items += member_func(section.member, desc, '')