From 81c522ae12066423251331bbf8b7974ca895bf66 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 9 Nov 2016 13:11:52 +0530 Subject: [PATCH] A better repr implementation for Line --- kitty/line.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kitty/line.c b/kitty/line.c index 5ca368c10..6b78545a9 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -78,6 +78,15 @@ as_unicode(Line* self) { return ans; } +static PyObject* +__repr__(Line* self) { + PyObject *s = as_unicode(self); + if (s == NULL) return NULL; + PyObject *ans = PyObject_Repr(s); + Py_CLEAR(s); + return ans; +} + static PyObject* width(Line *self, PyObject *val) { #define width_doc "width_doc(x) -> the width of the character at x" @@ -325,7 +334,8 @@ PyTypeObject Line_Type = { .tp_name = "fast_data_types.Line", .tp_basicsize = sizeof(Line), .tp_dealloc = (destructor)dealloc, - .tp_repr = (reprfunc)as_unicode, + .tp_repr = (reprfunc)__repr__, + .tp_str = (reprfunc)as_unicode, .tp_as_sequence = &sequence_methods, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_richcompare = richcmp,