[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: |
Wed, 17 Feb 2021 10:21:09 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
John Snow <jsnow@redhat.com> writes:
> On 2/16/21 11:08 AM, Markus Armbruster wrote:
>> John Snow <jsnow@redhat.com> writes:
>>
>>> On 2/16/21 3:55 AM, Markus Armbruster wrote:
>>>> John Snow <jsnow@redhat.com> writes:
[...]
>>>>> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
>>>>> index 353e8020a27..ff16578f6de 100644
>>>>> --- a/scripts/qapi/schema.py
>>>>> +++ b/scripts/qapi/schema.py
>>>>> @@ -28,7 +28,7 @@
>>>>> class QAPISchemaEntity:
>>>>> meta: Optional[str] = None
>>>>> - def __init__(self, name, info, doc, ifcond=None,
>>>>> features=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 []:
>>>>> assert isinstance(f, QAPISchemaFeature)
>>>>
>>>> How is this hunk related to typing introspect.py
>>>>
>>>
>>> I forget!
>>>
>>> qapi/introspect.py:262: error: Returning Any from function declared to
>>> return "str"
>>> Found 1 error in 1 file (checked 14 source files)
>>>
>>> Oh, for this reason:
>>>
>>> if isinstance(typ, QAPISchemaBuiltinType):
>>> return typ.name
>>>
>>> _use_type has a return type that is dependent upon the type of
>>> "typ.name", which required typing the QAPISchemaEntity initializer.
>>>
>>>
>>> (Do you want this in its own preceding patch?)
>>
>> That would work.
>> Keeping it in this patch with a suitable hint in the commit message
>> would also work. Up to you. If you want me to tweak in my tree, tell
>> me how.
>>
>
> We can try:
>
> "Annotations are also added to the QAPISchemaEntity __init__ method in
> schema.py to allow mypy to statically prove the type of typ.name,
> needed to prove the return type of
> QAPISchemaGenIntrospectVisitor._use_type()."
Sold!
- [PATCH v6 13/19] qapi/introspect.py: remove _gen_variants helper, (continued)
- [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
[PATCH v6 17/19] qapi/introspect.py: Type _gen_tree variants as Sequence[str], John Snow, 2021/02/15