diff mbox series

[02/25] qapi/schema.py: Move meta-type into class instances

Message ID 20200922224501.4087749-3-jsnow@redhat.com
State New
Headers show
Series qapi: static typing conversion, pt6 | expand

Commit Message

John Snow Sept. 22, 2020, 10:44 p.m. UTC
We are using meta as a class variable, but union types use this as a
mutable value which changes the value for the class, not the instance.

Use the empty string as the default/empty value for ease of typing. It
is still false-ish, so it will work just fine.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/schema.py | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 55434f5c82..0201b42095 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -17,7 +17,6 @@ 
 import os
 import re
 from collections import OrderedDict
-from typing import Optional
 
 from .common import c_name, POINTER_SUFFIX
 from .error import QAPISourceError, QAPISemError
@@ -32,8 +31,6 @@  def visit(self, visitor: 'QAPISchemaVisitor') -> None:
 
 
 class QAPISchemaEntity(Visitable):
-    meta: Optional[str] = None
-
     def __init__(self, name: str, info, doc, ifcond=None, features=None):
         assert name is None or isinstance(name, str)
         for f in features or []:
@@ -51,6 +48,15 @@  def __init__(self, name: str, info, doc, ifcond=None, features=None):
         self._ifcond = ifcond or []
         self.features = features or []
         self._checked = False
+        self._meta = ''
+
+    @property
+    def meta(self) -> str:
+        return self._meta
+
+    @meta.setter
+    def meta(self, value: str) -> None:
+        self._meta = value
 
     def c_name(self):
         return c_name(self.name)
@@ -212,8 +218,6 @@  def describe(self):
 
 
 class QAPISchemaBuiltinType(QAPISchemaType):
-    meta = 'built-in'
-
     def __init__(self, name, json_type, c_type):
         super().__init__(name, None, None)
         assert not c_type or isinstance(c_type, str)
@@ -221,6 +225,7 @@  def __init__(self, name, json_type, c_type):
                              'value')
         self._json_type_name = json_type
         self._c_type_name = c_type
+        self._meta = 'built-in'
 
     def c_name(self):
         return self.name
@@ -245,8 +250,6 @@  def visit(self, visitor):
 
 
 class QAPISchemaEnumType(QAPISchemaType):
-    meta = 'enum'
-
     def __init__(self, name, info, doc, ifcond, features, members, prefix):
         super().__init__(name, info, doc, ifcond, features)
         for m in members:
@@ -255,6 +258,7 @@  def __init__(self, name, info, doc, ifcond, features, members, prefix):
         assert prefix is None or isinstance(prefix, str)
         self.members = members
         self.prefix = prefix
+        self._meta = 'enum'
 
     def check(self, schema):
         super().check(schema)
@@ -289,13 +293,12 @@  def visit(self, visitor):
 
 
 class QAPISchemaArrayType(QAPISchemaType):
-    meta = 'array'
-
     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._meta = 'array'
 
     def check(self, schema):
         super().check(schema)
@@ -344,7 +347,7 @@  def __init__(self, name, info, doc, ifcond, features,
         # flat union has base, variants, and no local_members
         # simple union has local_members, variants, and no base
         super().__init__(name, info, doc, ifcond, features)
-        self.meta = 'union' if variants else 'struct'
+        self._meta = 'union' if variants else 'struct'
         assert base is None or isinstance(base, str)
         for m in local_members:
             assert isinstance(m, QAPISchemaObjectTypeMember)
@@ -456,8 +459,6 @@  def visit(self, visitor):
 
 
 class QAPISchemaAlternateType(QAPISchemaType):
-    meta = 'alternate'
-
     def __init__(self, name, info, doc, ifcond, features, variants):
         super().__init__(name, info, doc, ifcond, features)
         assert isinstance(variants, QAPISchemaVariants)
@@ -465,6 +466,7 @@  def __init__(self, name, info, doc, ifcond, features, variants):
         variants.set_defined_in(name)
         variants.tag_member.set_defined_in(self.name)
         self.variants = variants
+        self._meta = 'alternate'
 
     def check(self, schema):
         super().check(schema)
@@ -716,8 +718,6 @@  def __init__(self, name, info, typ, ifcond=None):
 
 
 class QAPISchemaCommand(QAPISchemaEntity):
-    meta = 'command'
-
     def __init__(self, name, info, doc, ifcond, features,
                  arg_type, ret_type,
                  gen, success_response, boxed, allow_oob, allow_preconfig):
@@ -733,6 +733,7 @@  def __init__(self, name, info, doc, ifcond, features,
         self.boxed = boxed
         self.allow_oob = allow_oob
         self.allow_preconfig = allow_preconfig
+        self._meta = 'command'
 
     def check(self, schema):
         super().check(schema)
@@ -779,14 +780,13 @@  def visit(self, visitor):
 
 
 class QAPISchemaEvent(QAPISchemaEntity):
-    meta = 'event'
-
     def __init__(self, name, info, doc, ifcond, features, arg_type, boxed):
         super().__init__(name, info, doc, ifcond, features)
         assert not arg_type or isinstance(arg_type, str)
         self._arg_type_name = arg_type
         self.arg_type = None
         self.boxed = boxed
+        self._meta = 'event'
 
     def check(self, schema):
         super().check(schema)