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 <js...@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