[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 03/14] qapi/doc.py: Add assertion on section.member
From: |
John Snow |
Subject: |
[PATCH 03/14] qapi/doc.py: Add assertion on section.member |
Date: |
Tue, 22 Sep 2020 17:17:51 -0400 |
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(-)
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, '')
--
2.26.2
- [PATCH 00/14] qapi: static typing conversion, pt3, John Snow, 2020/09/22
- [PATCH 01/14] qapi/doc.py: stash long temporary locals in named locals, John Snow, 2020/09/22
- [PATCH 02/14] qapi/doc.py: avoid unnecessary keyword arguments, John Snow, 2020/09/22
- [PATCH 03/14] qapi/doc.py: Add assertion on section.member,
John Snow <=
- [PATCH 07/14] qapi/doc.py: enable mypy checks, John Snow, 2020/09/22
- [PATCH 10/14] qapi/gen.py: Add __bool__ dunder method to QAPIGen, John Snow, 2020/09/22
- [PATCH 12/14] qapi/doc.py: Assert tag member is Enum type, John Snow, 2020/09/22
- [PATCH 13/14] qapi/doc.py: Assert type of object variant, John Snow, 2020/09/22
- [PATCH 11/14] qapi/doc.py: Don't use private attributes of QAPIGen property, John Snow, 2020/09/22