declare, but don't initialize the type of "type" to be QAPISchemaType - and allow the value to be initialized during check().
This avoids the need for several "assert type is not None" statements littered throughout the code by asserting it "will always be set." It's a little hokey, but it works -- at the expense of slightly incorrect type information before check() is called, anyway. If this field is accessed before it is initialized, 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 0fb44452dd5..c5fdd625452 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -771,7 +771,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(). Kind of hokey. self.optional = optional self.features = features or [] -- 2.41.0