Skip to contentSkip to conversation

qapi/parser: Mollify mypy

PATCH In review Markus Armbruster 3 participants 4 messages Nov 5, 2025 – Nov 10, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi/parser: Mollify mypy

re.match(r'^ *', ...) can't fail, but mypy doesn't know that and complains:

scripts/qapi/parser.py:444: error: Item "None" of "Match[str] | None" has no attribute "end" [union-attr]

Work around by using must_match() instead.

Fixes 8107ba47fd78 (qapi: Add documentation format validation)
---
 scripts/qapi/parser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi/parser.py +1 -1
index 1bb1af7051..c3cf33904e 100644
@@ -441,7 +441,7 @@ def get_doc_line(self) -> Optional[str]:
             self._literal_mode = True
             self._literal_mode_indent = 0
         elif self._literal_mode and line:
-            indent = re.match(r'^ *', line).end()
+            indent = must_match(r'\s*', line).end()
             if self._literal_mode_indent == 0:
                 self._literal_mode_indent = indent
             elif indent < self._literal_mode_indent:
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Markus Armbruster

re.match(r'^ *', ...) can't fail, but mypy doesn't know that and complains:

scripts/qapi/parser.py:444: error: Item "None" of "Match[str] | None" has no attribute "end" [union-attr]

Work around by using must_match() instead.

Fixes 8107ba47fd78 (qapi: Add documentation format validation)
Signature · 2 lines
Best regards,
Vladimir
#2 lore raw
In reply to Markus Armbruster
Quoted 18 lines · Markus Armbruster

re.match(r'^ *', ...) can't fail, but mypy doesn't know that and complains:

scripts/qapi/parser.py:444: error: Item "None" of "Match[str] | None" has no attribute "end" [union-attr]

Work around by using must_match() instead.

Fixes 8107ba47fd78 (qapi: Add documentation format validation)
---
  scripts/qapi/parser.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi/parser.py +0 -0
index 1bb1af7051..c3cf33904e 100644

scripts/qapi/parser.py def get_doc_line(self) -> Optional[str]: · line 447

Quoted 8 lines
scripts/qapi/parser.py +1 -1
@@ -441,7 +441,7 @@ def get_doc_line(self) -> Optional[str]:
              self._literal_mode = True
              self._literal_mode_indent = 0
          elif self._literal_mode and line:
-            indent = re.match(r'^ *', line).end()
+            indent = must_match(r'\s*', line).end()
              if self._literal_mode_indent == 0:
                  self._literal_mode_indent = indent
              elif indent < self._literal_mode_indent:

Thanks. I'm going to queue this so that it's in the next CI run.

r~

#3 lore raw
Quoted 17 lines · Richard Henderson
Quoted 16 lines · Markus Armbruster

re.match(r'^ *', ...) can't fail, but mypy doesn't know that and
complains:
scripts/qapi/parser.py:444: error: Item "None" of "Match[str] | None" has no attribute "end" [union-attr]
Work around by using must_match() instead.

Fixes 8107ba47fd78 (qapi: Add documentation format validation)
---
  scripts/qapi/parser.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
scripts/qapi/parser.py +0 -0
index 1bb1af7051..c3cf33904e 100644
@@ -441,7 +441,7 @@ def get_doc_line(self) -> Optional[str]:
              self._literal_mode = True
              self._literal_mode_indent = 0
Quoted 8 lines

scripts/qapi/parser.py def get_doc_line(self) -> Optional[str]: · line 447

Quoted 6 lines
scripts/qapi/parser.py +1 -1
          elif self._literal_mode and line:
-            indent = re.match(r'^ *', line).end()
+            indent = must_match(r'\s*', line).end()
              if self._literal_mode_indent == 0:
                  self._literal_mode_indent = indent
              elif indent < self._literal_mode_indent:

Thanks. I'm going to queue this so that it's in the next CI run.

Yes, please!