qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3] qapi: provide a friendly string representation of QAPI cl


From: Markus Armbruster
Subject: Re: [PATCH v3] qapi: provide a friendly string representation of QAPI classes
Date: Wed, 18 Oct 2023 14:37:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

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:
>
>   <qapi.schema.QAPISchemaEnumType object at 0x7f0ab4c2dad0>
>   <qapi.schema.QAPISchemaObjectType object at 0x7f0ab4c2dd90>
>   <qapi.schema.QAPISchemaArrayType object at 0x7f0ab4c2df90>
>
> With this change we instead get the classname and the human friendly
> name of the QAPI type instance:
>
>   <QAPISchemaEnumType:CpuS390State at 0x7f0ab4c2dad0>
>   <QAPISchemaObjectType:CpuInfoS390 at 0x7f0ab4c2dd90>
>   <QAPISchemaArrayType:CpuInfoFastList at 0x7f0ab4c2df90>
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>
> Changed in v3:
>
>  - Retain the object hex ID in the new representation
>
>  scripts/qapi/schema.py | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
> index 231ebf61ba..39c11bb52a 100644
> --- a/scripts/qapi/schema.py
> +++ b/scripts/qapi/schema.py
> @@ -73,6 +73,12 @@ def __init__(self, name: str, info, doc, ifcond=None, 
> features=None):
>          self.features = features or []
>          self._checked = False
>  
> +    def __repr__(self):
> +        if self.name is not None:
> +            return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, 
> id(self))
> +        else:
> +            return "<%s at 0x%x>" % (type(self).__name__, id(self))
> +
>      def c_name(self):
>          return c_name(self.name)

Looks good now.

Except I generally prefer

    if COND:
        SUITE1
    else:
        SUITE2

over

    if not COND:
        SUITE2
    else:
        SUITE1

because it avoids mental double-negation.
    
Mind if I swap things?  Like so:

    def __repr__(self):
        if self.name is None:
            return "<%s at 0x%x>" % (type(self).__name__, id(self))
        else:
            return "<%s:%s at 0x%x>" % (type(self).__name__,
                                        self.name, id(self))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]