OSDN Git Service

qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard
authorJohn Snow <jsnow@redhat.com>
Wed, 19 May 2021 18:39:47 +0000 (14:39 -0400)
committerMarkus Armbruster <armbru@redhat.com>
Thu, 20 May 2021 09:28:28 +0000 (11:28 +0200)
commit03386200b90c68953e217baedd3716cdee9ed169
tree23903345582e9b0da7f83e0686cd2dac0f23320b
parentc256263f3df0eaf9011405cdaee354380beb6dc5
qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard

TypeGuards wont exist in Python proper until 3.10. Ah well. We can hack
up our own by declaring this function to return the type we claim it
checks for and using this to safely downcast object -> List[str].

In so doing, I bring this function under _pragma so it can use the
'info' object in its closure. Having done this, _pragma also now no
longer needs to take a 'self' parameter, so drop it.

To help with line-length, and with the context evident from its new
scope, rename the function to the shorter check_list_str().

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