@@ -204,7 +204,7 @@ def _nodes_for_members(self, doc, what, base=None, branches=None):
None)
if branches:
- for v in branches.variants:
+ for v in branches:
if v.type.name == 'q_empty':
continue
assert not v.type.is_implicit()
@@ -342,7 +342,7 @@ def visit_object_type_flat(self, name: str, info: Optional[QAPISourceInfo],
}
if branches:
obj['tag'] = branches.tag_member.name
- obj['variants'] = [self._gen_variant(v) for v in branches.variants]
+ obj['variants'] = [self._gen_variant(v) for v in branches]
self._gen_tree(name, 'object', obj, ifcond, features)
def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo],
@@ -353,7 +353,7 @@ def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo],
name, 'alternate',
{'members': [Annotated({'type': self._use_type(m.type)},
m.ifcond)
- for m in alternatives.variants]},
+ for m in alternatives]},
ifcond, features
)
@@ -26,6 +26,7 @@
Any,
Callable,
Dict,
+ Iterator,
List,
Optional,
Union,
@@ -669,7 +670,7 @@ def check(self, schema: QAPISchema) -> None:
# so we have to check for potential name collisions ourselves.
seen: Dict[str, QAPISchemaMember] = {}
types_seen: Dict[str, str] = {}
- for v in self.alternatives.variants:
+ for v in self.alternatives:
v.check_clash(self.info, seen)
qtype = v.type.alternate_qtype()
if not qtype:
@@ -700,7 +701,7 @@ def check(self, schema: QAPISchema) -> None:
def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None:
super().connect_doc(doc)
doc = doc or self.doc
- for v in self.alternatives.variants:
+ for v in self.alternatives:
v.connect_doc(doc)
def c_type(self) -> str:
@@ -726,6 +727,9 @@ def __init__(
self.tag_member: QAPISchemaObjectTypeMember
self.variants = variants
+ def __iter__(self) -> Iterator[QAPISchemaVariant]:
+ return iter(self.variants)
+
def set_defined_in(self, name: str) -> None:
for v in self.variants:
v.set_defined_in(name)
@@ -166,7 +166,7 @@ def gen_object(name: str, ifcond: QAPISchemaIfCond,
objects_seen.add(name)
ret = ''
- for var in variants.variants if variants else ():
+ for var in variants or ():
obj = var.type
if not isinstance(obj, QAPISchemaObjectType):
continue
@@ -234,7 +234,7 @@ def gen_variants(variants: QAPISchemaVariants) -> str:
''',
c_name=c_name(variants.tag_member.name))
- for var in variants.variants:
+ for var in variants:
if var.type.name == 'q_empty':
continue
ret += var.ifcond.gen_if()
@@ -141,7 +141,7 @@ def gen_visit_object_members(name: str,
''',
c_name=c_name(tag_member.name))
- for var in branches.variants:
+ for var in branches:
case_str = c_enum_const(tag_member.type.name, var.name,
tag_member.type.prefix)
ret += var.ifcond.gen_if()
@@ -246,7 +246,7 @@ def gen_visit_alternate(name: str,
''',
c_name=c_name(name))
- for var in alternatives.variants:
+ for var in alternatives:
ret += var.ifcond.gen_if()
ret += mcgen('''
case %(case)s:
This just makes it easier to do something like: for var in variants: ... Instead of the more cumbersome and repetitive: for var in variants.variants: ... Especially in conjunction with entities that aren't guaranteed to have variants. Compare: for var in variants.variants if variants else []: ... against: for var in variants or []: ... Update callsites to reflect the new usage pattern. Signed-off-by: John Snow <jsnow@redhat.com> --- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/introspect.py | 4 ++-- scripts/qapi/schema.py | 8 ++++++-- scripts/qapi/types.py | 4 ++-- scripts/qapi/visit.py | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-)