QAPI patches patches for 2021-09-13

-----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEENUvIs9frKmtoZ05fOHC0AOuRhlMFAmE/A4YSHGFybWJydUBy
 ZWRoYXQuY29tAAoJEDhwtADrkYZTAQUQAILKa8kQmgXxDX7Hv7Ku/nSE895+I70J
 u7FJAX4Lwd2BhoalQvpSSDaNtBeJxG0QPasPSm8ztXswoS/u++CsPfoFJBktQ4W/
 sT+3HlcAfHzBup8hH7TCzuQuzCWUbzbs6VlVbiy8SuDUwz2hO/CmQYM/PXUXKDO7
 6XyW5eZFaMykaGrBsuDAHx2n5SoAZv2LucQtETUEYvaO64F3NlDAWsEAEhdKm74g
 90OcV91A5/egKUs1YlJFy4N9h85A51sEt6XeTE4cq47VVbtqZq2+EqZ67jBcTv4/
 5Ifnr4v3piTMcKAvtU1QvQL2mcn0dFHaixasRFgL0hJfL/gzVt6FUCm7i9mueD0p
 +cw/kwfCdQznXXtHQJjbAJnqnur4EZeLO4xvIM0/X6SdobE4WLf8uD+3bcmQV57P
 l5fj1YzTxCPbEr1YtGsjvJdAfS0l0gIXmuS5SuLNlYtPd0NH3n8joprE1BmA6nC4
 pHmw0XXofUgm515SpOAaHS8F4kjL2glCKwr/lX4EzCIMIIQqc8IKsCYoDalifuER
 5ZRMiGTwTXEv3CKwfA69m6LAhTrAGJb3vAIBX93JHRM+EYHN7L7DEsRiZtYShRdy
 vFuzb1TqpTwXUE+93sL97nk+X2V4LjX/PryXE4/Fz5ythKd7GAnv7T0nkMKQm8K7
 zYKuEEvil7nS
 =TkSi
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/armbru/tags/pull-qapi-2021-09-13' into staging

QAPI patches patches for 2021-09-13

# gpg: Signature made Mon 13 Sep 2021 08:53:42 BST
# gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
# gpg:                issuer "armbru@redhat.com"
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full]
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [full]
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-qapi-2021-09-13:
  qapi: Fix bogus error for 'if': { 'not': '' }
  tests/qapi-schema: Cover 'not' condition with empty argument
  qapi: Bury some unused code in class Indentation
  qapi: Drop Indentation.__bool__()
  qapi: Fix a botched type annotation

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
master
Peter Maydell 2021-09-13 11:00:30 +01:00
commit eae587e8e3
6 changed files with 25 additions and 21 deletions

View File

@ -132,9 +132,6 @@ class Indentation:
def __init__(self, initial: int = 0) -> None:
self._level = initial
def __int__(self) -> int:
return self._level
def __repr__(self) -> str:
return "{}({:d})".format(type(self).__name__, self._level)
@ -142,19 +139,13 @@ class Indentation:
"""Return the current indentation as a string of spaces."""
return ' ' * self._level
def __bool__(self) -> bool:
"""True when there is a non-zero indentation."""
return bool(self._level)
def increase(self, amount: int = 4) -> None:
"""Increase the indentation level by ``amount``, default 4."""
self._level += amount
def decrease(self, amount: int = 4) -> None:
"""Decrease the indentation level by ``amount``, default 4."""
if self._level < amount:
raise ArithmeticError(
f"Can't remove {amount:d} spaces from {self!r}")
assert amount <= self._level
self._level -= amount
@ -169,8 +160,9 @@ def cgen(code: str, **kwds: object) -> str:
Obey `indent`, and strip `EATSPACE`.
"""
raw = code % kwds
if indent:
raw = re.sub(r'^(?!(#|$))', str(indent), raw, flags=re.MULTILINE)
pfx = str(indent)
if pfx:
raw = re.sub(r'^(?!(#|$))', pfx, raw, flags=re.MULTILINE)
return re.sub(re.escape(EATSPACE) + r' *', '', raw)
@ -205,7 +197,8 @@ def gen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]],
cond_fmt: str, not_fmt: str,
all_operator: str, any_operator: str) -> str:
def do_gen(ifcond: Union[str, Dict[str, Any]], need_parens: bool):
def do_gen(ifcond: Union[str, Dict[str, Any]],
need_parens: bool) -> str:
if isinstance(ifcond, str):
return cond_fmt % ifcond
assert isinstance(ifcond, dict) and len(ifcond) == 1

View File

@ -293,17 +293,22 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None:
info,
"'if' condition of %s has conflicting keys" % source)
oper, operands = next(iter(cond.items()))
if 'not' in cond:
_check_if(cond['not'])
elif 'all' in cond:
_check_infix('all', cond['all'])
else:
_check_infix('any', cond['any'])
def _check_infix(operator: str, operands: object) -> None:
if not isinstance(operands, list):
raise QAPISemError(
info,
"'%s' condition of %s must be an array"
% (operator, source))
if not operands:
raise QAPISemError(
info, "'if' condition [] of %s is useless" % source)
if oper == "not":
_check_if(operands)
return
if oper in ("all", "any") and not isinstance(operands, list):
raise QAPISemError(
info, "'%s' condition of %s must be an array" % (oper, source))
for operand in operands:
_check_if(operand)

View File

@ -0,0 +1,2 @@
bad-if-not.json: In struct 'TestIfStruct':
bad-if-not.json:2: 'if' condition '' of struct is not a valid identifier

View File

@ -0,0 +1,3 @@
# check 'if not' with empy argument
{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' },
'if': { 'not': '' } }

View File

View File

@ -43,6 +43,7 @@ schemas = [
'bad-if-key.json',
'bad-if-keys.json',
'bad-if-list.json',
'bad-if-not.json',
'bad-type-bool.json',
'bad-type-dict.json',
'bad-type-int.json',