Skip to contentSkip to conversation

qapi/parser: Fix type hints

PATCH In review Markus Armbruster 3 participants 7 messages May 11, 2023 – May 22, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi/parser: Fix type hints

Fixes 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
---
 scripts/qapi/parser.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qapi/parser.py +2 -2
index 4923a59d60..9315412ab2 100644
@@ -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:
Signature · 1 line
2.39.2
#1 lore raw
Quoted 14 lines · Markus Armbruster
Fixes 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
---
  scripts/qapi/parser.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qapi/parser.py +0 -0
index 4923a59d60..9315412ab2 100644
@@ -563,11 +563,11 @@ def end_comment(self) -> None:
          self._switch_section(QAPIDoc.NullSection(self._parser))
 
      @staticmethod

scripts/qapi/parser.py def end_comment(self) -> None: · line 573

Quoted 10 lines
scripts/qapi/parser.py +2 -2
-    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~

#2 lore raw
Quoted 24 lines · Richard Henderson
Quoted 10 lines · Markus Armbruster
Fixes 3e32dca3f0d1 (qapi: Rewrite parsing of doc comment section symbols and tags)
---
  scripts/qapi/parser.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
scripts/qapi/parser.py +0 -0
index 4923a59d60..9315412ab2 100644

scripts/qapi/parser.py def end_comment(self) -> None: · line 570

Quoted 10 lines
scripts/qapi/parser.py +2 -2
@@ -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:

Quoted 5 lines

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.

#3 lore raw
Quoted 10 lines · Markus Armbruster
Quoted 5 lines

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~

#4 lore raw
Quoted 7 lines · Richard Henderson
Quoted 6 lines · Markus Armbruster
Quoted 5 lines

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

Quoted 7 lines
Quoted 3 lines

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: <[email protected]>

#5 lore raw
In reply to Markus Armbruster
Quoted 6 lines · Markus Armbruster
Quoted 3 lines

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

#6 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 7 lines · Markus Armbruster
Quoted 3 lines

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!