mirror of https://gitlab.com/qemu-project/qemu
qapi/parser: Fix token membership tests when token can be None
When the token can be None (EOF), we can't use 'x in "abc"' style membership tests to group types of tokens together, because 'None in "abc"' is a TypeError. Easy enough to fix. (Use a tuple: It's neither a static typing error nor a runtime error to check for None in Tuple[str, ...]) Add tests to prevent a regression. (Note: they cannot be added prior to this fix, as the unhandled stack trace will not match test output in the CI system.) Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210519183951.3946870-11-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
e0e8a0ac2e
commit
c256263f3d
|
@ -275,7 +275,7 @@ class QAPISchemaParser:
|
||||||
if self.tok == ']':
|
if self.tok == ']':
|
||||||
self.accept()
|
self.accept()
|
||||||
return expr
|
return expr
|
||||||
if self.tok not in "{['tf":
|
if self.tok not in tuple("{['tf"):
|
||||||
raise QAPIParseError(
|
raise QAPIParseError(
|
||||||
self, "expected '{', '[', ']', string, or boolean")
|
self, "expected '{', '[', ']', string, or boolean")
|
||||||
while True:
|
while True:
|
||||||
|
@ -294,7 +294,8 @@ class QAPISchemaParser:
|
||||||
elif self.tok == '[':
|
elif self.tok == '[':
|
||||||
self.accept()
|
self.accept()
|
||||||
expr = self.get_values()
|
expr = self.get_values()
|
||||||
elif self.tok in "'tf":
|
elif self.tok in tuple("'tf"):
|
||||||
|
assert isinstance(self.val, (str, bool))
|
||||||
expr = self.val
|
expr = self.val
|
||||||
self.accept()
|
self.accept()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -134,9 +134,11 @@ schemas = [
|
||||||
'indented-expr.json',
|
'indented-expr.json',
|
||||||
'leading-comma-list.json',
|
'leading-comma-list.json',
|
||||||
'leading-comma-object.json',
|
'leading-comma-object.json',
|
||||||
|
'missing-array-rsqb.json',
|
||||||
'missing-colon.json',
|
'missing-colon.json',
|
||||||
'missing-comma-list.json',
|
'missing-comma-list.json',
|
||||||
'missing-comma-object.json',
|
'missing-comma-object.json',
|
||||||
|
'missing-object-member-element.json',
|
||||||
'missing-type.json',
|
'missing-type.json',
|
||||||
'nested-struct-data.json',
|
'nested-struct-data.json',
|
||||||
'nested-struct-data-invalid-dict.json',
|
'nested-struct-data-invalid-dict.json',
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
missing-array-rsqb.json:1:44: expected '{', '[', string, or boolean
|
|
@ -0,0 +1 @@
|
||||||
|
['Daisy,', 'Daisy,', 'Give me your answer',
|
|
@ -0,0 +1 @@
|
||||||
|
missing-object-member-element.json:1:8: expected '{', '[', string, or boolean
|
|
@ -0,0 +1 @@
|
||||||
|
{'key':
|
Loading…
Reference in New Issue