[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 04/19] qapi/schema: declare type for QAPISchemaObjectTypeMembe
|
From: |
John Snow |
|
Subject: |
[PATCH v2 04/19] qapi/schema: declare type for QAPISchemaObjectTypeMember.type |
|
Date: |
Fri, 12 Jan 2024 17:29:30 -0500 |
declare, but don't initialize the type of "type" to be QAPISchemaType -
and allow the value to be initialized during check(). This creates a
form of delayed initialization for QAPISchemaType objects where the
static typing only represents the fully-realized object, which occurs
after check() has been called.
This avoids the need for several "assert type is not None" statements
littered throughout the code by asserting it "will always be set."
Note that the static typing information for this object will be
incorrect prior to check() being called. If this field is accessed
before it is initialized in check(), you'll be treated to an
AttributeError exception.
Fixes stuff like this:
qapi/schema.py:657: error: "None" has no attribute "alternate_qtype"
[attr-defined]
qapi/schema.py:662: error: "None" has no attribute "describe" [attr-defined]
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/schema.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index e39ed972a80..48a51dcd188 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -794,7 +794,7 @@ def __init__(self, name, info, typ, optional, ifcond=None,
features=None):
assert isinstance(f, QAPISchemaFeature)
f.set_defined_in(name)
self._type_name = typ
- self.type = None
+ self.type: QAPISchemaType # set during check()
self.optional = optional
self.features = features or []
--
2.43.0
- [PATCH v2 00/19] qapi: statically type schema.py, John Snow, 2024/01/12
- [PATCH v2 02/19] qapi/schema: add pylint suppressions, John Snow, 2024/01/12
- [PATCH v2 04/19] qapi/schema: declare type for QAPISchemaObjectTypeMember.type,
John Snow <=
- [PATCH v2 05/19] qapi/schema: declare type for QAPISchemaArrayType.element_type, John Snow, 2024/01/12
- [PATCH v2 08/19] qapi/schema: add type narrowing to lookup_type(), John Snow, 2024/01/12
- [PATCH v2 13/19] qapi/schema: split "checked" field into "checking" and "checked", John Snow, 2024/01/12
- [PATCH v2 11/19] qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type, John Snow, 2024/01/12