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: 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!




reply via email to

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