mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-21 06:58:36 -07:00
qapi/commands: assert arg_type is not None
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>
This commit is contained in:
parent
6f0e9c26db
commit
ec9697ab3f
1 changed files with 6 additions and 3 deletions
|
|
@ -126,6 +126,9 @@ def gen_marshal(name: str,
|
||||||
boxed: bool,
|
boxed: bool,
|
||||||
ret_type: Optional[QAPISchemaType]) -> str:
|
ret_type: Optional[QAPISchemaType]) -> str:
|
||||||
have_args = boxed or (arg_type and not arg_type.is_empty())
|
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('''
|
ret = mcgen('''
|
||||||
|
|
||||||
|
|
@ -147,7 +150,7 @@ def gen_marshal(name: str,
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
%(c_name)s arg = {0};
|
%(c_name)s arg = {0};
|
||||||
''',
|
''',
|
||||||
c_name=arg_type.c_name())
|
c_name=arg_type_c_name)
|
||||||
|
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
|
|
||||||
|
|
@ -163,7 +166,7 @@ def gen_marshal(name: str,
|
||||||
ok = visit_check_struct(v, errp);
|
ok = visit_check_struct(v, errp);
|
||||||
}
|
}
|
||||||
''',
|
''',
|
||||||
c_arg_type=arg_type.c_name())
|
c_arg_type=arg_type_c_name)
|
||||||
else:
|
else:
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
ok = visit_check_struct(v, errp);
|
ok = visit_check_struct(v, errp);
|
||||||
|
|
@ -193,7 +196,7 @@ out:
|
||||||
ret += mcgen('''
|
ret += mcgen('''
|
||||||
visit_type_%(c_arg_type)s_members(v, &arg, NULL);
|
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('''
|
ret += mcgen('''
|
||||||
visit_end_struct(v, NULL);
|
visit_end_struct(v, NULL);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue