All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Michael Roth <michael.roth@amd.com>,
	qemu-devel@nongnu.org, Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes
Date: Fri, 05 Mar 2021 14:18:08 +0100	[thread overview]
Message-ID: <87lfb120z3.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <20210302175524.1290840-4-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Tue, 2 Mar 2021 17:55:24 +0000")

Daniel P. Berrangé <berrange@redhat.com> writes:

> If printing a QAPI schema object for debugging we get the classname and
> a hex value for the instance. With this change we instead get the
> classname and the human friendly name of the QAPI type instance.
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  scripts/qapi/schema.py | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
> index ff16578f6d..800bc5994b 100644
> --- a/scripts/qapi/schema.py
> +++ b/scripts/qapi/schema.py
> @@ -46,6 +46,9 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None):
>          self.features = features or []
>          self._checked = False
>  
> +    def __repr__(self):
> +        return "%s<%s>" % (type(self).__name__, self.name)
> +
>      def c_name(self):
>          return c_name(self.name)

https://docs.python.org/3.6/reference/datamodel.html#object.__repr__

    Called by the repr() built-in function to compute the “official”
    string representation of an object.  If at all possible, this should
    look like a valid Python expression that could be used to recreate
    an object with the same value (given an appropriate environment).

Making QAPISchemaEntity.__repr__() return "a valid Python expression
that could be used to recreate an object with the same value" is
probably more trouble than it's worth.

    If this is not possible, a string of the form <...some useful
    description...> should be returned.

I'm afraid your .__repr__() has the < in the wrong place.

                                         The return value must be a
    __repr__() is also used when an “informal” string representation of
    instances of that class is required.

    This is typically used for debugging, so it is important that the
    representation is information-rich and unambiguous.


I guess your .__repr__() is unambiguous enough for practical purposes,
as entity names are typically unique within a schema.  *Except* for
QAPISchemaInclude, where self.name is always None.

What about self.name or id(self)?



      parent reply	other threads:[~2021-03-05 13:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 17:55 [PATCH 0/3] audio: make audiodev introspectable by mgmt apps Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 1/3] qapi, audio: add query-audiodev command Daniel P. Berrangé
2021-03-02 19:03   ` Eric Blake
2021-03-02 21:10   ` Philippe Mathieu-Daudé
2021-03-02 21:12     ` Philippe Mathieu-Daudé
2021-03-03 10:07       ` Daniel P. Berrangé
2021-03-03 10:08     ` Daniel P. Berrangé
2021-03-05 13:01   ` Markus Armbruster
2021-03-11 11:00     ` Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 2/3] qapi, audio: respect build time conditions in audio schema Daniel P. Berrangé
2021-03-02 19:05   ` Eric Blake
2021-03-03 10:09     ` Daniel P. Berrangé
2021-03-03  7:00   ` Gerd Hoffmann
2021-03-03 10:11     ` Daniel P. Berrangé
2021-03-05 10:56       ` Markus Armbruster
2021-03-11 11:04         ` Daniel P. Berrangé
2021-03-05 12:12   ` Markus Armbruster
2022-12-12 16:53   ` Thomas Huth
2022-12-14 11:28     ` Daniel P. Berrangé
2021-03-02 17:55 ` [PATCH 3/3] qapi: provide a friendly string representation of QAPI classes Daniel P. Berrangé
2021-03-02 19:06   ` Eric Blake
2021-03-02 21:02   ` Philippe Mathieu-Daudé
2021-03-05 13:18   ` Markus Armbruster [this message]

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=87lfb120z3.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=kraxel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.