mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 04:13:53 -06:00
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>
This commit is contained in:
parent
91416a4254
commit
2184bca7b1
5 changed files with 21 additions and 20 deletions
|
@ -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::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue