]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib/clippy: add a __repr__ for graph nodes
authorDavid Lamparter <equinox@opensourcerouting.org>
Sat, 20 Jul 2024 22:55:43 +0000 (15:55 -0700)
committerDonald Sharp <sharpd@nvidia.com>
Wed, 31 Jul 2024 12:08:53 +0000 (08:08 -0400)
Make it a little easier to work on python code using this wrapper.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/command_py.c

index 82ca5a8ffcd09127bbbad7605a1a28a0af76ce71..a80925d2d9452cb8cded52c1e989cc085b537e1e 100644 (file)
@@ -145,6 +145,14 @@ static void graph_node_wrap_free(void *arg)
        Py_DECREF(wrap->wgraph);
 }
 
+static PyObject *repr_graph_node(PyObject *arg)
+{
+       struct wrap_graph_node *wrap = (struct wrap_graph_node *)arg;
+
+       return PyUnicode_FromFormat("<_clippy.GraphNode %p [%zu] %s>",
+                                   wrap->node, wrap->idx, wrap->type);
+}
+
 static PyTypeObject typeobj_graph_node = {
        PyVarObject_HEAD_INIT(NULL, 0).tp_name = "_clippy.GraphNode",
        .tp_basicsize = sizeof(struct wrap_graph_node),
@@ -154,6 +162,7 @@ static PyTypeObject typeobj_graph_node = {
        .tp_free = graph_node_wrap_free,
        .tp_members = members_graph_node,
        .tp_methods = methods_graph_node,
+       .tp_repr = repr_graph_node,
 };
 
 static PyObject *graph_to_pyobj(struct wrap_graph *wgraph,