From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>
Cc: Michael Roth <michael.roth@amd.com>, John Snow <jsnow@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Cleber Rosa <crosa@redhat.com>
Subject: [PATCH v6 01/19] qapi: Replace List[str] with Sequence[str] for ifcond
Date: Mon, 15 Feb 2021 21:17:51 -0500 [thread overview]
Message-ID: <20210216021809.134886-2-jsnow@redhat.com> (raw)
In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com>
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 with a Mutable type like a List.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/commands.py | 3 ++-
scripts/qapi/events.py | 4 ++--
scripts/qapi/gen.py | 12 ++++++------
scripts/qapi/types.py | 12 ++++++------
scripts/qapi/visit.py | 10 +++++-----
5 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py
index 54af519f44d..0a75a9371ba 100644
--- a/scripts/qapi/commands.py
+++ b/scripts/qapi/commands.py
@@ -17,6 +17,7 @@
Dict,
List,
Optional,
+ Sequence,
Set,
)
@@ -297,7 +298,7 @@ def visit_end(self) -> None:
def visit_command(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
ret_type: Optional[QAPISchemaType],
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index 8c57deb2b89..90d2f6156d8 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -12,7 +12,7 @@
See the COPYING file in the top-level directory.
"""
-from typing import List, Optional
+from typing import List, Optional, Sequence
from .common import c_enum_const, c_name, mcgen
from .gen import QAPISchemaModularCVisitor, build_params, ifcontext
@@ -214,7 +214,7 @@ def visit_end(self) -> None:
def visit_event(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
arg_type: Optional[QAPISchemaObjectType],
boxed: bool) -> None:
diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py
index 63549cc8d47..1fa503bdbdf 100644
--- a/scripts/qapi/gen.py
+++ b/scripts/qapi/gen.py
@@ -17,8 +17,8 @@
from typing import (
Dict,
Iterator,
- List,
Optional,
+ Sequence,
Tuple,
)
@@ -85,7 +85,7 @@ def write(self, output_dir: str) -> None:
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 @@ def _bottom(self) -> str:
@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::
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index 2bdd6268476..20d572a23aa 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -13,7 +13,7 @@
# See the COPYING file in the top-level directory.
"""
-from typing import List, Optional
+from typing import List, Optional, Sequence
from .common import (
c_enum_const,
@@ -139,7 +139,7 @@ def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str:
return ret
-def gen_object(name: str, ifcond: List[str],
+def gen_object(name: str, ifcond: Sequence[str],
base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember],
variants: Optional[QAPISchemaVariants]) -> str:
@@ -307,7 +307,7 @@ def _gen_type_cleanup(self, name: str) -> None:
def visit_enum_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
members: List[QAPISchemaEnumMember],
prefix: Optional[str]) -> None:
@@ -318,7 +318,7 @@ def visit_enum_type(self,
def visit_array_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
element_type: QAPISchemaType) -> None:
with ifcontext(ifcond, self._genh, self._genc):
self._genh.preamble_add(gen_fwd_object_or_array(name))
@@ -328,7 +328,7 @@ def visit_array_type(self,
def visit_object_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember],
@@ -351,7 +351,7 @@ def visit_object_type(self,
def visit_alternate_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
variants: QAPISchemaVariants) -> None:
with ifcontext(ifcond, self._genh):
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 22e62df9017..9aa0b1e11e9 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -13,7 +13,7 @@
See the COPYING file in the top-level directory.
"""
-from typing import List, Optional
+from typing import List, Optional, Sequence
from .common import (
c_enum_const,
@@ -337,7 +337,7 @@ def _begin_user_module(self, name: str) -> None:
def visit_enum_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
members: List[QAPISchemaEnumMember],
prefix: Optional[str]) -> None:
@@ -348,7 +348,7 @@ def visit_enum_type(self,
def visit_array_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
element_type: QAPISchemaType) -> None:
with ifcontext(ifcond, self._genh, self._genc):
self._genh.add(gen_visit_decl(name))
@@ -357,7 +357,7 @@ def visit_array_type(self,
def visit_object_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
base: Optional[QAPISchemaObjectType],
members: List[QAPISchemaObjectTypeMember],
@@ -379,7 +379,7 @@ def visit_object_type(self,
def visit_alternate_type(self,
name: str,
info: Optional[QAPISourceInfo],
- ifcond: List[str],
+ ifcond: Sequence[str],
features: List[QAPISchemaFeature],
variants: QAPISchemaVariants) -> None:
with ifcontext(ifcond, self._genh, self._genc):
--
2.29.2
next prev parent reply other threads:[~2021-02-16 2:32 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-16 2:17 [PATCH v6 00/19] qapi: static typing conversion, pt2 John Snow
2021-02-16 2:17 ` John Snow [this message]
2021-02-16 8:43 ` [PATCH v6 01/19] qapi: Replace List[str] with Sequence[str] for ifcond Markus Armbruster
2021-02-16 15:19 ` John Snow
2021-02-16 15:58 ` Markus Armbruster
2021-02-16 2:17 ` [PATCH v6 02/19] qapi/introspect.py: assert schema is not None John Snow
2021-02-16 2:17 ` [PATCH v6 03/19] qapi/introspect.py: use _make_tree for features nodes John Snow
2021-02-16 2:17 ` [PATCH v6 04/19] qapi/introspect.py: add _gen_features helper John Snow
2021-02-16 2:17 ` [PATCH v6 05/19] qapi/introspect.py: guard against ifcond/comment misuse John Snow
2021-02-17 12:01 ` Markus Armbruster
2021-02-16 2:17 ` [PATCH v6 06/19] qapi/introspect.py: Unify return type of _make_tree() John Snow
2021-02-16 2:17 ` [PATCH v6 07/19] qapi/introspect.py: replace 'extra' dict with 'comment' argument John Snow
2021-02-16 2:17 ` [PATCH v6 08/19] qapi/introspect.py: Always define all 'extra' dict keys John Snow
2021-02-16 2:17 ` [PATCH v6 09/19] qapi/introspect.py: Introduce preliminary tree typing John Snow
2021-02-16 2:18 ` [PATCH v6 10/19] qapi/introspect.py: create a typed 'Annotated' data strutcure John Snow
2021-02-16 2:18 ` [PATCH v6 11/19] qapi/introspect.py: improve _tree_to_qlit error message John Snow
2021-02-16 2:18 ` [PATCH v6 12/19] qapi/introspect.py: improve readability of _tree_to_qlit John Snow
2021-02-16 2:18 ` [PATCH v6 13/19] qapi/introspect.py: remove _gen_variants helper John Snow
2021-02-16 2:18 ` [PATCH v6 14/19] qapi/introspect.py: add type hint annotations John Snow
2021-02-16 8:55 ` Markus Armbruster
2021-02-16 8:58 ` Markus Armbruster
2021-02-16 15:33 ` John Snow
2021-02-16 16:08 ` Markus Armbruster
2021-02-16 16:19 ` John Snow
2021-02-17 9:21 ` Markus Armbruster
2021-02-18 18:56 ` Markus Armbruster
2021-02-18 19:01 ` Markus Armbruster
2021-02-16 2:18 ` [PATCH v6 15/19] qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit John Snow
2021-02-17 9:39 ` Markus Armbruster
2021-02-17 16:07 ` John Snow
2021-02-17 16:35 ` Markus Armbruster
2021-02-17 16:55 ` John Snow
2021-02-18 7:53 ` Markus Armbruster
2021-02-16 2:18 ` [PATCH v6 16/19] qapi/introspect.py: Update copyright and authors list John Snow
2021-02-16 2:18 ` [PATCH v6 17/19] qapi/introspect.py: Type _gen_tree variants as Sequence[str] John Snow
2021-02-16 9:10 ` Markus Armbruster
2021-02-16 15:13 ` John Snow
2021-02-16 2:18 ` [PATCH v6 18/19] qapi/introspect.py: set _gen_tree's default ifcond argument to () John Snow
2021-02-16 2:18 ` [PATCH v6 19/19] qapi/introspect.py: add SchemaMetaType enum John Snow
2021-02-16 9:24 ` Markus Armbruster
2021-02-16 15:08 ` John Snow
2021-02-16 16:09 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210216021809.134886-2-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=ehabkost@redhat.com \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).