[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/16] qapi/commands: assert arg_type is not None
From: |
Markus Armbruster |
Subject: |
[PULL 01/16] qapi/commands: assert arg_type is not None |
Date: |
Mon, 8 Feb 2021 14:58:31 +0100 |
From: John Snow <jsnow@redhat.com>
When boxed is True, expr.py asserts that we must have
arguments. Ultimately, this should mean that if boxed is True that
arg_type should be defined. Mypy cannot infer this, and does not support
'stateful' type inference, e.g.:
```
if x:
assert y is not None
...
if x:
y.etc()
```
does not work, because mypy does not statefully remember the conditional
assertion in the second block. Help mypy out by creating a new local
that it can track more easily.
Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210201193747.2169670-2-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
scripts/qapi/commands.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 50978090b4..71744f48a3 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -126,6 +126,9 @@ def gen_marshal(name: str,
boxed: bool,
ret_type: Optional[QAPISchemaType]) -> str:
have_args = boxed or (arg_type and not arg_type.is_empty())
+ if have_args:
+ assert arg_type is not None
+ arg_type_c_name = arg_type.c_name()
ret = mcgen('''
@@ -147,7 +150,7 @@ def gen_marshal(name: str,
ret += mcgen('''
%(c_name)s arg = {0};
''',
- c_name=arg_type.c_name())
+ c_name=arg_type_c_name)
ret += mcgen('''
@@ -163,7 +166,7 @@ def gen_marshal(name: str,
ok = visit_check_struct(v, errp);
}
''',
- c_arg_type=arg_type.c_name())
+ c_arg_type=arg_type_c_name)
else:
ret += mcgen('''
ok = visit_check_struct(v, errp);
@@ -193,7 +196,7 @@ out:
ret += mcgen('''
visit_type_%(c_arg_type)s_members(v, &arg, NULL);
''',
- c_arg_type=arg_type.c_name())
+ c_arg_type=arg_type_c_name)
ret += mcgen('''
visit_end_struct(v, NULL);
--
2.26.2
- [PULL 00/16] QAPI patches patches for 2021-02-08, Markus Armbruster, 2021/02/08
- [PULL 04/16] qapi/gen: inline _wrap_ifcond into end_if(), Markus Armbruster, 2021/02/08
- [PULL 02/16] qapi/events: fix visit_event typing, Markus Armbruster, 2021/02/08
- [PULL 12/16] qapi/gen: Support switching to another module temporarily, Markus Armbruster, 2021/02/08
- [PULL 01/16] qapi/commands: assert arg_type is not None,
Markus Armbruster <=
- [PULL 13/16] qapi/commands: Simplify command registry generation, Markus Armbruster, 2021/02/08
- [PULL 07/16] qapi: use explicitly internal module names, Markus Armbruster, 2021/02/08
- [PULL 03/16] qapi/main: handle theoretical None-return from re.match(), Markus Armbruster, 2021/02/08
- [PULL 06/16] qapi/gen: Replace ._begin_system_module(), Markus Armbruster, 2021/02/08
- [PULL 05/16] qapi: centralize is_[user|system|builtin]_module methods, Markus Armbruster, 2021/02/08
- [PULL 16/16] qapi: enable strict-optional checks, Markus Armbruster, 2021/02/08
- [PULL 11/16] qapi/gen: write _genc/_genh access shims, Markus Armbruster, 2021/02/08
- [PULL 15/16] qapi: type 'info' as Optional[QAPISourceInfo], Markus Armbruster, 2021/02/08
- [PULL 10/16] qapi: centralize the built-in module name definition, Markus Armbruster, 2021/02/08
- [PULL 14/16] qapi/gen: Drop support for QAPIGen without a file name, Markus Armbruster, 2021/02/08