qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, "Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 03/10] qapi/introspect: Use @dataclass to simplify
Date: Thu,  6 Mar 2025 10:35:54 +0100	[thread overview]
Message-ID: <20250306093601.2264772-4-armbru@redhat.com> (raw)
In-Reply-To: <20250306093601.2264772-1-armbru@redhat.com>

A TODO comment in class Annotated reminds us to simplify it once we
can use @dataclass, new in Python 3.7.  We have that now, so do it.

There's a similar comment in scripts/qapi/source.py, but I can't
figure out how to use @dataclass there.  Left for another day.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20250227080757.3978333-4-armbru@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
 scripts/qapi/introspect.py | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 42e5185c7c..89ee5d5f17 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -11,6 +11,7 @@
 See the COPYING file in the top-level directory.
 """
 
+from dataclasses import dataclass
 from typing import (
     Any,
     Dict,
@@ -79,19 +80,16 @@
 _ValueT = TypeVar('_ValueT', bound=_Value)
 
 
+@dataclass
 class Annotated(Generic[_ValueT]):
     """
     Annotated generally contains a SchemaInfo-like type (as a dict),
     But it also used to wrap comments/ifconds around scalar leaf values,
     for the benefit of features and enums.
     """
-    # TODO: Remove after Python 3.7 adds @dataclass:
-    # pylint: disable=too-few-public-methods
-    def __init__(self, value: _ValueT, ifcond: QAPISchemaIfCond,
-                 comment: Optional[str] = None):
-        self.value = value
-        self.comment: Optional[str] = comment
-        self.ifcond = ifcond
+    value: _ValueT
+    ifcond: QAPISchemaIfCond
+    comment: Optional[str] = None
 
 
 def _tree_to_qlit(obj: JSONValue,
-- 
2.48.1



  parent reply	other threads:[~2025-03-06  9:38 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 ` [PULL 02/10] qapi: Eliminate OrderedDict Markus Armbruster
2025-03-06  9:35 ` Markus Armbruster [this message]
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-4-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).