qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v6 14/19] qapi/introspect.py: add type hint annotations


From: Markus Armbruster
Subject: Re: [PATCH v6 14/19] qapi/introspect.py: add type hint annotations
Date: Tue, 16 Feb 2021 09:58:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Markus Armbruster <armbru@redhat.com> writes:

> John Snow <jsnow@redhat.com> writes:
>
>> NB: The type aliases (SchemaInfo et al) declare intent for some of the
>> "dictly-typed" objects we pass around in introspect.py. They do not
>> enforce the shape of those objects, and cannot, until Python 3.7 or
>> later. (And even then, it may not be "worth it".)
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>  scripts/qapi/introspect.py | 124 +++++++++++++++++++++++++++----------
>>  scripts/qapi/mypy.ini      |   5 --
>>  scripts/qapi/schema.py     |   2 +-
>>  3 files changed, 92 insertions(+), 39 deletions(-)
>>
>> diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
>> index b0fcc4443c1..45284af1330 100644
>> --- a/scripts/qapi/introspect.py
>> +++ b/scripts/qapi/introspect.py
[...]
>> @@ -216,10 +237,13 @@ def _use_type(self, typ):
>>          return self._name(typ.name)
>>  
>>      @staticmethod
>> -    def _gen_features(features):
>> +    def _gen_features(features: List[QAPISchemaFeature]
>> +                      ) -> List[Annotated[str]]:
>>          return [Annotated(f.name, f.ifcond) for f in features]
>>  
>> -    def _gen_tree(self, name, mtype, obj, ifcond, features):
>> +    def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object],
>
> Schould this be obj: SchemaInfo?

No, because @obj is incomplete; _gen_tree() completes it.

>
>> +                  ifcond: Sequence[str],
>> +                  features: Optional[List[QAPISchemaFeature]]) -> None:
>>          comment: Optional[str] = None
>>          if mtype not in ('command', 'event', 'builtin', 'array'):
>>              if not self._unmask:
[...]




reply via email to

[Prev in Thread] Current Thread [Next in Thread]