[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/19] qapi/schema: make QAPISchemaArrayType.element_type non-Opt
|
From: |
John Snow |
|
Subject: |
[PATCH 10/19] qapi/schema: make QAPISchemaArrayType.element_type non-Optional |
|
Date: |
Wed, 15 Nov 2023 20:43:41 -0500 |
This field should always be present and defined. Change this to be a
runtime @property that can emit an error if it's called prior to
check().
This helps simplify typing by avoiding the need to interrogate the value
for None at multiple callsites.
RFC: Yes, this is a slightly different technique than the one I used for
QAPISchemaObjectTypeMember.type; I think I prefer this one as being a
little less hokey, but it is more SLOC. Dealer's choice for which style
wins out -- now you have an example of both.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/schema.py | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index c9a194103e1..462acb2bb61 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -366,7 +366,16 @@ def __init__(self, name, info, element_type):
super().__init__(name, info, None)
assert isinstance(element_type, str)
self._element_type_name = element_type
- self.element_type = None
+ self._element_type: Optional[QAPISchemaType] = None
+
+ @property
+ def element_type(self) -> QAPISchemaType:
+ if self._element_type is None:
+ raise RuntimeError(
+ "QAPISchemaArray has no element_type until "
+ "after check() has been run."
+ )
+ return self._element_type
def need_has_if_optional(self):
# When FOO is an array, we still need has_FOO to distinguish
@@ -375,7 +384,7 @@ def need_has_if_optional(self):
def check(self, schema):
super().check(schema)
- self.element_type = schema.resolve_type(
+ self._element_type = schema.resolve_type(
self._element_type_name, self.info,
self.info and self.info.defn_meta)
assert not isinstance(self.element_type, QAPISchemaArrayType)
--
2.41.0
- Re: [PATCH 12/19] qapi/schema: split "checked" field into "checking" and "checked", (continued)
[PATCH 10/19] qapi/schema: make QAPISchemaArrayType.element_type non-Optional,
John Snow <=
[PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, John Snow, 2023/11/15
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Philippe Mathieu-Daudé, 2023/11/16
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Markus Armbruster, 2023/11/21
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Daniel P . Berrangé, 2023/11/21
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, John Snow, 2023/11/21
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Daniel P . Berrangé, 2023/11/21
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Markus Armbruster, 2023/11/22
- Re: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods, Daniel P . Berrangé, 2023/11/22