[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 01/11] qapi/commands: assert arg_type is not None
From: |
Markus Armbruster |
Subject: |
[PATCH 01/11] qapi/commands: assert arg_type is not None |
Date: |
Fri, 18 Dec 2020 21:53:57 +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: <20201217015927.197287-2-jsnow@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
- [PATCH 00/11] Drop support for QAPIGen without a file name, Markus Armbruster, 2020/12/18
- [PATCH 01/11] qapi/commands: assert arg_type is not None,
Markus Armbruster <=
- [PATCH 04/11] qapi/gen: assert that _start_if is not None in _wrap_ifcond, Markus Armbruster, 2020/12/18
- [PATCH 03/11] qapi/main: handle theoretical None-return from re.match(), Markus Armbruster, 2020/12/18
- [PATCH 07/11] qapi/gen: Replace ._begin_system_module(), Markus Armbruster, 2020/12/18
- [PATCH 06/11] qapi/gen: write _genc/_genh access shims, Markus Armbruster, 2020/12/18
- [PATCH 11/11] qapi/gen: Drop support for QAPIGen without a file name, Markus Armbruster, 2020/12/18
- [PATCH 02/11] qapi/events: fix visit_event typing, Markus Armbruster, 2020/12/18
- [PATCH 08/11] qapi/gen: Expose a single module name space, Markus Armbruster, 2020/12/18
- [PATCH 09/11] qapi/gen: Support for switching to another module temporarily, Markus Armbruster, 2020/12/18
- [PATCH 05/11] qapi/gen: use './builtin' for the built-in module name, Markus Armbruster, 2020/12/18
- [PATCH 10/11] qapi/commands: Simplify command registry generation, Markus Armbruster, 2020/12/18