[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:
[...]
- [PATCH v6 08/19] qapi/introspect.py: Always define all 'extra' dict keys, (continued)
- [PATCH v6 08/19] qapi/introspect.py: Always define all 'extra' dict keys, John Snow, 2021/02/15
- [PATCH v6 05/19] qapi/introspect.py: guard against ifcond/comment misuse, John Snow, 2021/02/15
- [PATCH v6 09/19] qapi/introspect.py: Introduce preliminary tree typing, John Snow, 2021/02/15
- [PATCH v6 13/19] qapi/introspect.py: remove _gen_variants helper, John Snow, 2021/02/15
- [PATCH v6 04/19] qapi/introspect.py: add _gen_features helper, John Snow, 2021/02/15
- [PATCH v6 12/19] qapi/introspect.py: improve readability of _tree_to_qlit, John Snow, 2021/02/15
- [PATCH v6 11/19] qapi/introspect.py: improve _tree_to_qlit error message, John Snow, 2021/02/15
- [PATCH v6 14/19] qapi/introspect.py: add type hint annotations, John Snow, 2021/02/15
Re: [PATCH v6 14/19] qapi/introspect.py: add type hint annotations, Markus Armbruster, 2021/02/18
[PATCH v6 15/19] qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit, John Snow, 2021/02/15