diff options
author | Markus Armbruster <armbru@redhat.com> | 2025-02-27 09:07:57 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2025-03-06 10:09:25 +0100 |
commit | e6985cc4407ddb14a27a282efc0b4c8d34534317 (patch) | |
tree | a96c6c7b171c4504156516fc31901f3f6bb9bfc9 /scripts/qapi/introspect.py | |
parent | 5fbc8126acaf07a0294f8f94f4c244c3c5b62d5d (diff) | |
download | qemu-e6985cc4407ddb14a27a282efc0b4c8d34534317.zip qemu-e6985cc4407ddb14a27a282efc0b4c8d34534317.tar.gz qemu-e6985cc4407ddb14a27a282efc0b4c8d34534317.tar.bz2 |
qapi/introspect: Use @dataclass to simplify
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>
Diffstat (limited to 'scripts/qapi/introspect.py')
-rw-r--r-- | scripts/qapi/introspect.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 42e5185..89ee5d5 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -11,6 +11,7 @@ This work is licensed under the terms of the GNU GPL, version 2. See the COPYING file in the top-level directory. """ +from dataclasses import dataclass from typing import ( Any, Dict, @@ -79,19 +80,16 @@ SchemaInfoCommand = Dict[str, object] _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, |