[PATCH v2 05/19] qapi/schema: declare type for QAPISchemaArrayType.element_type

John Snow posted 19 patches 10 months ago
Maintainers: Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>
There is a newer version of this series
[PATCH v2 05/19] qapi/schema: declare type for QAPISchemaArrayType.element_type
Posted by John Snow 10 months ago
This field should always be present and defined after check() is
called. Declare the property but allow its initialization to be delayed
until check() so that it can be typed without the use of `Optional`.

This helps simplify typing by avoiding the need to interrogate the value
for None at multiple callsites; the overwhelming majority of uses assume
a fully-initialized object.

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 48a51dcd188..e45d9545eda 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -389,7 +389,7 @@ 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: QAPISchemaType
 
     def need_has_if_optional(self):
         # When FOO is an array, we still need has_FOO to distinguish
-- 
2.43.0
Re: [PATCH v2 05/19] qapi/schema: declare type for QAPISchemaArrayType.element_type
Posted by Markus Armbruster 10 months ago
John Snow <jsnow@redhat.com> writes:

> This field should always be present and defined after check() is
> called. Declare the property but allow its initialization to be delayed
> until check() so that it can be typed without the use of `Optional`.
>
> This helps simplify typing by avoiding the need to interrogate the value
> for None at multiple callsites; the overwhelming majority of uses assume
> a fully-initialized object.

If you like my version of the previous patch's commit message, we could
reuse it here.

> 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 48a51dcd188..e45d9545eda 100644
> --- a/scripts/qapi/schema.py
> +++ b/scripts/qapi/schema.py
> @@ -389,7 +389,7 @@ 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: QAPISchemaType
>  
>      def need_has_if_optional(self):
>          # When FOO is an array, we still need has_FOO to distinguish
Re: [PATCH v2 05/19] qapi/schema: declare type for QAPISchemaArrayType.element_type
Posted by John Snow 10 months ago
On Mon, Jan 15, 2024 at 8:59 AM Markus Armbruster <armbru@redhat.com> wrote:
>
> John Snow <jsnow@redhat.com> writes:
>
> > This field should always be present and defined after check() is
> > called. Declare the property but allow its initialization to be delayed
> > until check() so that it can be typed without the use of `Optional`.
> >
> > This helps simplify typing by avoiding the need to interrogate the value
> > for None at multiple callsites; the overwhelming majority of uses assume
> > a fully-initialized object.
>
> If you like my version of the previous patch's commit message, we could
> reuse it here.

Sure, I tweaked and re-used it.

--js

>
> > 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 48a51dcd188..e45d9545eda 100644
> > --- a/scripts/qapi/schema.py
> > +++ b/scripts/qapi/schema.py
> > @@ -389,7 +389,7 @@ 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: QAPISchemaType
> >
> >      def need_has_if_optional(self):
> >          # When FOO is an array, we still need has_FOO to distinguish
>