qapi: provide a friendly string representation of QAPI classes
PATCH v2 1/1 qapi: provide a friendly string representation of QAPI classes
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>
<QAPISchemaObjectType:CpuInfoS390>
<QAPISchemaArrayType:CpuInfoFastList>
---
v1 was two & half years ago:
https://mail.gnu.org/archive/html/qemu-devel/2021-03/msg01645.html
scripts/qapi/schema.py | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/qapi/schema.py +6 -0
@@ -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>" % (type(self).__name__, self.name) + else: + return "<%s>" % type(self).__name__ + def c_name(self): return c_name(self.name)
Signature · 1 line
2.41.0
Quoted 7 lines · Daniel P. Berrangé
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 at0x7f0ab4c2dd90> <qapi.schema.QAPISchemaArrayType object at0x7f0ab4c2df90>
Quoted 6 lines
With this change we instead get the classname and the human friendly name of the QAPI type instance:
<QAPISchemaEnumType:CpuS390State>
<QAPISchemaObjectType:CpuInfoS390>
<QAPISchemaArrayType:CpuInfoFastList>
This gains the QAPI name (good), but loses the address. The actual address is rarely useful (when it is, you're deep in Python innards; good luck, you'll need it). Except they let me see which objects are the same, and which are different. Could that be preserved without trouble somehow?
Quoted 6 lines
Signed-off-by Daniel P. Berrangé <[email protected]>---
v1 was two & half years ago:
https://mail.gnu.org/archive/html/qemu-devel/2021-03/msg01645.html
Was it my fault? If yes, I apologize.
Quoted 19 lines
scripts/qapi/schema.py | 6 ++++++ 1 file changed, 6 insertions(+)scripts/qapi/schema.py +6
-0@@ -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>" % (type(self).__name__, self.name) + else: + return "<%s>" % type(self).__name__ + def c_name(self): return c_name(self.name)
Quoted 16 lines · Markus Armbruster
Quoted 7 lines · Daniel P. Berrangé
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 at0x7f0ab4c2dd90> <qapi.schema.QAPISchemaArrayType object at0x7f0ab4c2df90>Quoted 6 lines
With this change we instead get the classname and the human friendly name of the QAPI type instance:
<QAPISchemaEnumType:CpuS390State>
<QAPISchemaObjectType:CpuInfoS390>
<QAPISchemaArrayType:CpuInfoFastList>
Quoted 5 lines
This gains the QAPI name (good), but loses the address. The actual address is rarely useful (when it is, you're deep in Python innards; good luck, you'll need it). Except they let me see which objects are the same, and which are different. Could that be preserved without trouble somehow?
It appears the hex value comes from 'id(obj)', so yes, I can insert the same hex value into the new representation.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Daniel P. Berrangé <[email protected]>---
v1 was two & half years ago:
https://mail.gnu.org/archive/html/qemu-devel/2021-03/msg01645.html
Was it my fault? If yes, I apologize.
No, I forgot about it until I was moving old branches from my previous laptop to my new laptops :-)
Quoted 12 lines
Quoted 12 lines
scripts/qapi/schema.py | 6 ++++++ 1 file changed, 6 insertions(+)scripts/qapi/schema.py +0
-0@@ -73,6 +73,12 @@ def __init__(self, name: str, info, doc, ifcond=None, features=None): self.features = features or [] self._checked = False
Quoted 9 lines
scripts/qapi/schema.py def __init__(self, name: str, info, doc, ifcond=None, features=None): · line 83
Quoted 8 lines
scripts/qapi/schema.py +6
-0+ def __repr__(self): + if self.name is not None: + return "<%s:%s>" % (type(self).__name__, self.name) + else: + return "<%s>" % type(self).__name__ + def c_name(self): return c_name(self.name)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 17 lines · Daniel P. Berrangé
Quoted 16 lines · Markus Armbruster
Quoted 13 lines · Daniel P. Berrangé
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 at0x7f0ab4c2dd90> <qapi.schema.QAPISchemaArrayType object at0x7f0ab4c2df90>With this change we instead get the classname and the human friendly name of the QAPI type instance:
<QAPISchemaEnumType:CpuS390State>
<QAPISchemaObjectType:CpuInfoS390>
<QAPISchemaArrayType:CpuInfoFastList>
Quoted 8 lines
Quoted 5 lines
This gains the QAPI name (good), but loses the address. The actual address is rarely useful (when it is, you're deep in Python innards; good luck, you'll need it). Except they let me see which objects are the same, and which are different. Could that be preserved without trouble somehow?
It appears the hex value comes from 'id(obj)', so yes, I can insert the same hex value into the new representation.
I'd appreciate that.
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
Signed-off-by Daniel P. Berrangé <[email protected]>---
v1 was two & half years ago:
https://mail.gnu.org/archive/html/qemu-devel/2021-03/msg01645.html
Was it my fault? If yes, I apologize.
No, I forgot about it until I was moving old branches from my previous laptop to my new laptops :-)
Puh!
[...]