[PATCH] qapi/parser: Fix type hints

Markus Armbruster posted 1 patch 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230511111709.971477-1-armbru@redhat.com
Maintainers: Markus Armbruster <armbru@redhat.com>, Michael Roth <michael.roth@amd.com>
scripts/qapi/parser.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] qapi/parser: Fix type hints
Posted by Markus Armbruster 12 months ago
Fixes: 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/parser.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 4923a59d60..9315412ab2 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -563,11 +563,11 @@ def end_comment(self) -> None:
         self._switch_section(QAPIDoc.NullSection(self._parser))
 
     @staticmethod
-    def _match_at_name_colon(string: str) -> re.Match:
+    def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
         return re.match(r'@([^:]*): *', string)
 
     @staticmethod
-    def _match_section_tag(string: str) -> re.Match:
+    def _match_section_tag(string: str) -> Optional[re.Match[str]]:
         return re.match(r'(Returns|Since|Notes?|Examples?|TODO): *', string)
 
     def _append_body_line(self, line: str) -> None:
-- 
2.39.2
Re: [PATCH] qapi/parser: Fix type hints
Posted by Richard Henderson 11 months, 3 weeks ago
On 5/11/23 04:17, Markus Armbruster wrote:
> Fixes: 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>   scripts/qapi/parser.py | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 4923a59d60..9315412ab2 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -563,11 +563,11 @@ def end_comment(self) -> None:
>           self._switch_section(QAPIDoc.NullSection(self._parser))
>   
>       @staticmethod
> -    def _match_at_name_colon(string: str) -> re.Match:
> +    def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>           return re.match(r'@([^:]*): *', string)
>   
>       @staticmethod
> -    def _match_section_tag(string: str) -> re.Match:
> +    def _match_section_tag(string: str) -> Optional[re.Match[str]]:
>           return re.match(r'(Returns|Since|Notes?|Examples?|TODO): *', string)
>   
>       def _append_body_line(self, line: str) -> None:

Doesn't work:

https://gitlab.com/qemu-project/qemu/-/jobs/4289613692#L574

   File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
     def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
TypeError: 'type' object is not subscriptable


r~
Re: [PATCH] qapi/parser: Fix type hints
Posted by Markus Armbruster 11 months, 3 weeks ago
Richard Henderson <richard.henderson@linaro.org> writes:

> On 5/11/23 04:17, Markus Armbruster wrote:
>> Fixes: 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>   scripts/qapi/parser.py | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
>> index 4923a59d60..9315412ab2 100644
>> --- a/scripts/qapi/parser.py
>> +++ b/scripts/qapi/parser.py
>> @@ -563,11 +563,11 @@ def end_comment(self) -> None:
>>           self._switch_section(QAPIDoc.NullSection(self._parser))
>>         @staticmethod
>> -    def _match_at_name_colon(string: str) -> re.Match:
>> +    def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>>           return re.match(r'@([^:]*): *', string)
>>         @staticmethod
>> -    def _match_section_tag(string: str) -> re.Match:
>> +    def _match_section_tag(string: str) -> Optional[re.Match[str]]:
>>           return re.match(r'(Returns|Since|Notes?|Examples?|TODO): *', string)
>>         def _append_body_line(self, line: str) -> None:
>
> Doesn't work:
>
> https://gitlab.com/qemu-project/qemu/-/jobs/4289613692#L574
>
>   File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
>     def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
> TypeError: 'type' object is not subscriptable

Life's too short for wrestling with such pigs.  Unless John has better
ideas, I'll *remove* these return type annotations.  Maybe these pigs
will behave after John's Python venv work lands.
Re: [PATCH] qapi/parser: Fix type hints
Posted by Paolo Bonzini 11 months, 3 weeks ago
On 5/16/23 07:22, Markus Armbruster wrote:
>>    File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
>>      def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>> TypeError: 'type' object is not subscriptable
> Life's too short for wrestling with such pigs.  Unless John has better
> ideas, I'll*remove*  these return type annotations.  Maybe these pigs
> will behave after John's Python venv work lands.

re.Match[str] is new in 3.9.  However, typing.Match[str] should work.

Paolo
Re: [PATCH] qapi/parser: Fix type hints
Posted by Markus Armbruster 11 months, 2 weeks ago
Paolo Bonzini <pbonzini@redhat.com> writes:

> On 5/16/23 07:22, Markus Armbruster wrote:
>>>    File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
>>>      def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>>> TypeError: 'type' object is not subscriptable
>>
>> Life's too short for wrestling with such pigs.  Unless John has better
>> ideas, I'll *remove*  these return type annotations.  Maybe these pigs
>> will behave after John's Python venv work lands.
>
> re.Match[str] is new in 3.9.  However, typing.Match[str] should work.

We'll try that after John's venv work is in.  Thank you!
Re: [PATCH] qapi/parser: Fix type hints
Posted by Richard Henderson 11 months, 3 weeks ago
On 5/15/23 22:22, Markus Armbruster wrote:
>> https://gitlab.com/qemu-project/qemu/-/jobs/4289613692#L574
>>
>>    File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
>>      def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>> TypeError: 'type' object is not subscriptable
> 
> Life's too short for wrestling with such pigs.  Unless John has better
> ideas, I'll *remove* these return type annotations.  Maybe these pigs
> will behave after John's Python venv work lands.
> 

That is exactly the idea that I had as well.

r~
Re: [PATCH] qapi/parser: Fix type hints
Posted by Markus Armbruster 11 months, 3 weeks ago
Richard Henderson <richard.henderson@linaro.org> writes:

> On 5/15/23 22:22, Markus Armbruster wrote:
>>> https://gitlab.com/qemu-project/qemu/-/jobs/4289613692#L574
>>>
>>>    File "/builds/qemu-project/qemu/scripts/qapi/parser.py", line 566, in QAPIDoc
>>>      def _match_at_name_colon(string: str) -> Optional[re.Match[str]]:
>>> TypeError: 'type' object is not subscriptable
>> 
>> Life's too short for wrestling with such pigs.  Unless John has better
>> ideas, I'll *remove* these return type annotations.  Maybe these pigs
>> will behave after John's Python venv work lands.
>
> That is exactly the idea that I had as well.
>
> r~

Sent:

Subject: [PATCH] qapi/parser: Drop two bad type hints for now
Message-Id: <20230517061600.1782455-1-armbru@redhat.com>