[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
- [PATCH v2 00/11] qapi: static typing conversion, pt2, John Snow, 2020/10/26
- [PATCH v2 02/11] [DO-NOT-MERGE] docs/sphinx: change default role to "any", John Snow, 2020/10/26
- [PATCH v2 11/11] qapi/introspect.py: Add docstring to _tree_to_qlit, John Snow, 2020/10/26
- [PATCH v2 04/11] qapi/introspect.py: add assertions and casts,
John Snow <=
- [PATCH v2 03/11] [DO-NOT-MERGE] docs: enable sphinx-autodoc for scripts/qapi, John Snow, 2020/10/26
- [PATCH v2 06/11] qapi/introspect.py: add _gen_features helper, John Snow, 2020/10/26
- [PATCH v2 08/11] qapi/introspect.py: replace 'extra' dict with 'comment' argument, John Snow, 2020/10/26
- [PATCH v2 07/11] qapi/introspect.py: Unify return type of _make_tree(), John Snow, 2020/10/26
- [PATCH v2 10/11] qapi/introspect.py: improve readability of _tree_to_qlit, John Snow, 2020/10/26
- [PATCH v2 01/11] [DO-NOT-MERGE] docs: replace single backtick (`) with double-backtick (``), John Snow, 2020/10/26
- [PATCH v2 09/11] qapi/introspect.py: create a typed 'Annotated' data strutcure, John Snow, 2020/10/26
- [PATCH v2 05/11] qapi/introspect.py: add preliminary type hint annotations, John Snow, 2020/10/26