diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2024-07-20 15:55:43 -0700 |
|---|---|---|
| committer | Donald Sharp <sharpd@nvidia.com> | 2024-07-31 08:08:53 -0400 |
| commit | f85e58af12ae3ebff84262af6b7d15a137875881 (patch) | |
| tree | ab2124f97ddc16c45bcfb75b84bc3e6a959a31fe | |
| parent | 34a4f858b7823c07fd1d7faa385f6a692136fc2f (diff) | |
lib/clippy: add a __repr__ for graph nodes
Make it a little easier to work on python code using this wrapper.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
| -rw-r--r-- | lib/command_py.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/command_py.c b/lib/command_py.c index 82ca5a8ffc..a80925d2d9 100644 --- a/lib/command_py.c +++ b/lib/command_py.c @@ -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, |
