[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 39/46] qapi/introspect.py: Unify return type of _make_tree()
From: |
John Snow |
Subject: |
[PATCH v4 39/46] qapi/introspect.py: Unify return type of _make_tree() |
Date: |
Wed, 30 Sep 2020 00:31:43 -0400 |
Returning a *something* or a Tuple of *something* is hard to accurately
type. Let's just always return a tuple for structural consistency.
Instances of the 'TreeNode' type can be replaced with the slightly more
specific 'AnnotatedNode' type.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/introspect.py | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 5cbdc7414bd..1c3ba41f1dc 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -53,14 +53,12 @@
def _make_tree(obj: Union[_DObject, str], ifcond: List[str],
extra: Optional[Extra] = None
- ) -> Union[TreeNode, AnnotatedNode]:
+ ) -> AnnotatedNode:
if extra is None:
extra = {}
if ifcond:
extra['if'] = ifcond
- if extra:
- return (obj, extra)
- return obj
+ return (obj, extra)
def _tree_to_qlit(obj: TreeNode,
@@ -128,7 +126,7 @@ def __init__(self, prefix: str, unmask: bool):
' * QAPI/QMP schema introspection', __doc__)
self._unmask = unmask
self._schema: Optional[QAPISchema] = None
- self._trees: List[TreeNode] = []
+ self._trees: List[AnnotatedNode] = []
self._used_types: List[QAPISchemaType] = []
self._name_map: Dict[str, str] = {}
self._genc.add(mcgen('''
@@ -195,7 +193,8 @@ def _use_type(self, typ: QAPISchemaType) -> str:
@classmethod
def _gen_features(cls,
- features: List[QAPISchemaFeature]) -> List[TreeNode]:
+ features: List[QAPISchemaFeature]
+ ) -> List[AnnotatedNode]:
return [_make_tree(f.name, f.ifcond) for f in features]
def _gen_tree(self, name: str, mtype: str, obj: _DObject,
@@ -215,7 +214,7 @@ def _gen_tree(self, name: str, mtype: str, obj: _DObject,
self._trees.append(_make_tree(obj, ifcond, extra))
def _gen_member(self,
- member: QAPISchemaObjectTypeMember) -> TreeNode:
+ member: QAPISchemaObjectTypeMember) -> AnnotatedNode:
obj: _DObject = {
'name': member.name,
'type': self._use_type(member.type)
@@ -231,7 +230,7 @@ def _gen_variants(self, tag_name: str,
return {'tag': tag_name,
'variants': [self._gen_variant(v) for v in variants]}
- def _gen_variant(self, variant: QAPISchemaVariant) -> TreeNode:
+ def _gen_variant(self, variant: QAPISchemaVariant) -> AnnotatedNode:
obj: _DObject = {
'case': variant.name,
'type': self._use_type(variant.type)
--
2.26.2
- [PATCH v4 35/46] qapi/gen.py: delint with pylint, (continued)
- [PATCH v4 35/46] qapi/gen.py: delint with pylint, John Snow, 2020/09/30
- [PATCH v4 36/46] qapi/introspect.py: assert obj is a dict when features are given, John Snow, 2020/09/30
- [PATCH v4 38/46] qapi/introspect.py: add _gen_features helper, John Snow, 2020/09/30
- [PATCH v4 40/46] qapi/introspect.py: replace 'extra' dict with 'comment' argument, John Snow, 2020/09/30
- [PATCH v4 42/46] qapi/types.py: add type hint annotations, John Snow, 2020/09/30
- [PATCH v4 44/46] qapi/visit.py: assert tag_member contains a QAPISchemaEnumType, John Snow, 2020/09/30
- [PATCH v4 45/46] qapi/visit.py: remove unused parameters from gen_visit_object, John Snow, 2020/09/30
- [PATCH v4 39/46] qapi/introspect.py: Unify return type of _make_tree(),
John Snow <=
[PATCH v4 41/46] qapi/introspect.py: create a typed 'Node' data structure, John Snow, 2020/09/30
[PATCH v4 37/46] qapi/instrospect.py: add preliminary type hint annotations, John Snow, 2020/09/30