qapi/expr.py: Add casts in a few select cases
commit7a783ce5b5a3ac4762b866e22370dd4fb30b91bf
authorJohn Snow <jsnow@redhat.com>
Wed, 21 Apr 2021 18:20:23 +0000 (21 14:20 -0400)
committerMarkus Armbruster <armbru@redhat.com>
Fri, 30 Apr 2021 10:59:54 +0000 (30 12:59 +0200)
tree65c8884bd2830681e1ca26a71a1d5feb70777951
parent4918bb7defbdcb1e27cc2adf4e1604486d778ece
qapi/expr.py: Add casts in a few select cases

Casts are instructions to the type checker only, they aren't "safe" and
should probably be avoided in general. In this case, when we perform
type checking on a nested structure, the type of each field does not
"stick".

(See PEP 647 for an example of "type narrowing" that does "stick".
 It is available in Python 3.10, so we can't use it yet.)

We don't need to assert that something is a str if we've already checked
or asserted that it is -- use a cast instead for these cases.

Signed-off-by: John Snow <jsnow@redhat.com>
Message-Id: <20210421182032.3521476-9-jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
scripts/qapi/expr.py