From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, "Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 02/10] qapi: Eliminate OrderedDict
Date: Thu, 6 Mar 2025 10:35:53 +0100 [thread overview]
Message-ID: <20250306093601.2264772-3-armbru@redhat.com> (raw)
In-Reply-To: <20250306093601.2264772-1-armbru@redhat.com>
We use OrderedDict to ensure dictionary order is insertion order.
Plain dict does that since Python 3.6, but it wasn't guaranteed until
3.7. Since we have 3.7 now, replace OrderedDict by dict.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20250227080757.3978333-3-armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
scripts/qapi/parser.py | 5 ++---
scripts/qapi/schema.py | 11 +++++------
tests/qapi-schema/test-qapi.py | 11 +----------
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index adc85b5b39..64f0bb824a 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -14,7 +14,6 @@
# This work is licensed under the terms of the GNU GPL, version 2.
# See the COPYING file in the top-level directory.
-from collections import OrderedDict
import os
import re
from typing import (
@@ -154,7 +153,7 @@ def _parse(self) -> None:
"value of 'include' must be a string")
incl_fname = os.path.join(os.path.dirname(self._fname),
include)
- self._add_expr(OrderedDict({'include': incl_fname}), info)
+ self._add_expr({'include': incl_fname}, info)
exprs_include = self._include(include, info, incl_fname,
self._included)
if exprs_include:
@@ -355,7 +354,7 @@ def accept(self, skip_comment: bool = True) -> None:
raise QAPIParseError(self, "stray '%s'" % match.group(0))
def get_members(self) -> Dict[str, object]:
- expr: Dict[str, object] = OrderedDict()
+ expr: Dict[str, object] = {}
if self.tok == '}':
self.accept()
return expr
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 7f70969c09..cbe3b5aa91 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -19,7 +19,6 @@
from __future__ import annotations
from abc import ABC, abstractmethod
-from collections import OrderedDict
import os
import re
from typing import (
@@ -557,7 +556,7 @@ def check(self, schema: QAPISchema) -> None:
super().check(schema)
assert self._checked and not self._check_complete
- seen = OrderedDict()
+ seen = {}
if self._base_name:
self.base = schema.resolve_type(self._base_name, self.info,
"'base'")
@@ -1141,10 +1140,10 @@ def __init__(self, fname: str):
self.docs = parser.docs
self._entity_list: List[QAPISchemaEntity] = []
self._entity_dict: Dict[str, QAPISchemaDefinition] = {}
- self._module_dict: Dict[str, QAPISchemaModule] = OrderedDict()
+ self._module_dict: Dict[str, QAPISchemaModule] = {}
# NB, values in the dict will identify the first encountered
# usage of a named feature only
- self._feature_dict: Dict[str, QAPISchemaFeature] = OrderedDict()
+ self._feature_dict: Dict[str, QAPISchemaFeature] = {}
# All schemas get the names defined in the QapiSpecialFeature enum.
# Rely on dict iteration order matching insertion order so that
@@ -1454,7 +1453,7 @@ def _def_command(self, expr: QAPIExpression) -> None:
ifcond = QAPISchemaIfCond(expr.get('if'))
info = expr.info
features = self._make_features(expr.get('features'), info)
- if isinstance(data, OrderedDict):
+ if isinstance(data, dict):
data = self._make_implicit_object_type(
name, info, ifcond,
'arg', self._make_members(data, info))
@@ -1473,7 +1472,7 @@ def _def_event(self, expr: QAPIExpression) -> None:
ifcond = QAPISchemaIfCond(expr.get('if'))
info = expr.info
features = self._make_features(expr.get('features'), info)
- if isinstance(data, OrderedDict):
+ if isinstance(data, dict):
data = self._make_implicit_object_type(
name, info, ifcond,
'arg', self._make_members(data, info))
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index 7e3f9f4aa1..8fe951c880 100755
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -96,17 +96,8 @@ def _print_variants(variants):
@staticmethod
def _print_if(ifcond, indent=4):
- # TODO Drop this hack after replacing OrderedDict by plain
- # dict (requires Python 3.7)
- def _massage(subcond):
- if isinstance(subcond, str):
- return subcond
- if isinstance(subcond, list):
- return [_massage(val) for val in subcond]
- return {key: _massage(val) for key, val in subcond.items()}
-
if ifcond.is_present():
- print('%sif %s' % (' ' * indent, _massage(ifcond.ifcond)))
+ print('%sif %s' % (' ' * indent, ifcond.ifcond))
@classmethod
def _print_features(cls, features, indent=4):
--
2.48.1
next prev parent reply other threads:[~2025-03-06 9:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 9:35 [PULL 00/10] QAPI patches patches for 2025-03-06 Markus Armbruster
2025-03-06 9:35 ` [PULL 01/10] docs/about/build-platforms: Correct minimum supported Python version Markus Armbruster
2025-03-06 9:35 ` Markus Armbruster [this message]
2025-03-06 9:35 ` [PULL 03/10] qapi/introspect: Use @dataclass to simplify Markus Armbruster
2025-03-06 9:35 ` [PULL 04/10] qdev: Delete unused qdev_prop_enum Markus Armbruster
2025-03-06 9:35 ` [PULL 05/10] qdev: Change qdev_prop_pci_devfn member @name from "int32" to "str" Markus Armbruster
2025-03-06 9:35 ` [PULL 06/10] qdev: Rename PropertyInfo member @name to @type Markus Armbruster
2025-03-06 9:35 ` [PULL 07/10] qdev: Change values of PropertyInfo member @type to be QAPI types Markus Armbruster
2025-03-06 9:35 ` [PULL 08/10] qdev: Improve PropertyInfo member @description for enum properties Markus Armbruster
2025-03-06 9:36 ` [PULL 09/10] qdev: Improve a few more PropertyInfo @description members Markus Armbruster
2025-03-06 9:36 ` [PULL 10/10] docs/devel/qapi-code-gen: Discourage use of 'prefix' Markus Armbruster
2025-03-07 7:18 ` [PULL 00/10] QAPI patches patches for 2025-03-06 Stefan Hajnoczi
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=20250306093601.2264772-3-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).