aboutsummaryrefslogtreecommitdiff
path: root/scripts/qapi/gen.py
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2021-02-15 21:17:51 -0500
committerMarkus Armbruster <armbru@redhat.com>2021-02-18 17:10:29 +0100
commit2184bca7b17559107032ba4fd8fc6f65345276ed (patch)
tree8ce7e157281f96233f1fa60adc95a50207ee8286 /scripts/qapi/gen.py
parent91416a4254015e1e3f602f2b241b9ddb7879c10b (diff)
downloadqemu-2184bca7b17559107032ba4fd8fc6f65345276ed.zip
qemu-2184bca7b17559107032ba4fd8fc6f65345276ed.tar.gz
qemu-2184bca7b17559107032ba4fd8fc6f65345276ed.tar.bz2
qapi: Replace List[str] with Sequence[str] for ifcond
It does happen to be a list (as of now), but we can describe it in more general terms with no loss in accuracy to allow tuples and other constructs. In the future, we can write "ifcond: Sequence[str] = ()" as a default parameter, which we could not do safely with a Mutable type like a List. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20210216021809.134886-2-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Commit message tweaked] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'scripts/qapi/gen.py')
-rw-r--r--scripts/qapi/gen.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 63549cc..1fa503b 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -17,8 +17,8 @@ import re
from typing import (
Dict,
Iterator,
- List,
Optional,
+ Sequence,
Tuple,
)
@@ -85,7 +85,7 @@ class QAPIGen:
fp.write(text)
-def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str:
+def _wrap_ifcond(ifcond: Sequence[str], before: str, after: str) -> str:
if before == after:
return after # suppress empty #if ... #endif
@@ -127,9 +127,9 @@ def build_params(arg_type: Optional[QAPISchemaObjectType],
class QAPIGenCCode(QAPIGen):
def __init__(self, fname: str):
super().__init__(fname)
- self._start_if: Optional[Tuple[List[str], str, str]] = None
+ self._start_if: Optional[Tuple[Sequence[str], str, str]] = None
- def start_if(self, ifcond: List[str]) -> None:
+ def start_if(self, ifcond: Sequence[str]) -> None:
assert self._start_if is None
self._start_if = (ifcond, self._body, self._preamble)
@@ -187,11 +187,11 @@ class QAPIGenH(QAPIGenC):
@contextmanager
-def ifcontext(ifcond: List[str], *args: QAPIGenCCode) -> Iterator[None]:
+def ifcontext(ifcond: Sequence[str], *args: QAPIGenCCode) -> Iterator[None]:
"""
A with-statement context manager that wraps with `start_if()` / `end_if()`.
- :param ifcond: A list of conditionals, passed to `start_if()`.
+ :param ifcond: A sequence of conditionals, passed to `start_if()`.
:param args: any number of `QAPIGenCCode`.
Example::