qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 04/11] qapi/introspect.py: add assertions and casts


From: John Snow
Subject: [PATCH v2 04/11] qapi/introspect.py: add assertions and casts
Date: Mon, 26 Oct 2020 15:42:44 -0400

This is necessary to keep mypy passing in the next patch when we add
preliminary type hints. It will be removed shortly.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/introspect.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index fafec94e022..63f721ebfb6 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -10,6 +10,8 @@
 See the COPYING file in the top-level directory.
 """
 
+from typing import Optional, Sequence, cast
+
 from .common import (
     c_name,
     gen_endif,
@@ -30,6 +32,7 @@ def _make_tree(obj, ifcond, features, extra=None):
     if ifcond:
         extra['if'] = ifcond
     if features:
+        assert isinstance(obj, dict)
         obj['features'] = [(f.name, {'if': f.ifcond}) for f in features]
     if extra:
         return (obj, extra)
@@ -43,7 +46,7 @@ def indent(level):
 
     if isinstance(obj, tuple):
         ifobj, extra = obj
-        ifcond = extra.get('if')
+        ifcond = cast(Optional[Sequence[str]], extra.get('if'))
         comment = extra.get('comment')
         ret = ''
         if comment:
-- 
2.26.2




reply via email to

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