diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2021-09-13 11:00:30 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2021-09-13 11:00:30 +0100 |
| commit | eae587e8e3694b1aceab23239493fb4c7e1a80f5 (patch) | |
| tree | 7214c3b0c00ebeca6d3338692216057f132fd5a9 /scripts/qapi/common.py | |
| parent | 99c44988d5ba1866a411450c877ed818b1b70081 (diff) | |
| parent | 62f27589f8549d6cf1f7fe21ed55ce6f2f705450 (diff) | |
| download | focaccia-qemu-eae587e8e3694b1aceab23239493fb4c7e1a80f5.tar.gz focaccia-qemu-eae587e8e3694b1aceab23239493fb4c7e1a80f5.zip | |
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>
Diffstat (limited to 'scripts/qapi/common.py')
| -rw-r--r-- | scripts/qapi/common.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 5f8f76e5b2..489273574a 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -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 |