]> sigrok.org Git - libsigrok.git/commitdiff
bindings/python: More user-friendly class string representation
authorMarc Schink <redacted>
Fri, 29 Mar 2024 12:38:23 +0000 (13:38 +0100)
committerSoeren Apel <redacted>
Thu, 20 Nov 2025 18:00:54 +0000 (19:00 +0100)
Add a function to generate a more descriptive and user-friendly class
string representation using class attributes.

Signed-off-by: Marc Schink <redacted>
bindings/python/sigrok/core/classes.i

index b0b7fcfa94dc06899a8357331a7047de734a6d0f..325983d7f943a1325211440099da9f1cc87d8aa4 100644 (file)
@@ -81,6 +81,15 @@ typedef guint pyg_flags_type;
 
 %include "../../../swig/templates.i"
 
+%pythoncode
+{
+    def _class_attribute_repr(obj, attributes):
+        attribute_str = ", ".join(
+            ["%s=%s" % (key, repr(obj.__getattribute__(key))) for key in attributes]
+        )
+        return "{:s} ({:s})".format(obj.__class__.__name__, attribute_str)
+}
+
 /* Map file objects to file descriptors. */
 %typecheck(SWIG_TYPECHECK_POINTER) int fd {
     $1 = (PyObject_AsFileDescriptor($input) != -1);