From 1f7002d8a2f4c7cfba9f10e1d771812dd91977b6 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 21 Nov 2019 09:26:41 +0000 Subject: int: Ensure we stringify Booleans as 0 or 1 Python 3.8 removes the tp_str for various built-in types, so we would print Boolean values as their repr (for example dbus.Boolean(True)), which is a regression. Print them as 0 or 1 instead, which was the historical behaviour (arguably False or True would be better, but that would be a behaviour change). Signed-off-by: Simon McVittie --- dbus_bindings/int.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dbus_bindings/int.c b/dbus_bindings/int.c index 696f93e..5944314 100644 --- a/dbus_bindings/int.c +++ b/dbus_bindings/int.c @@ -80,6 +80,12 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) return self; } +static PyObject * +Boolean_tp_str(PyObject *self) +{ + return PyUnicode_FromString(PyObject_IsTrue(self) ? "1" : "0"); +} + static PyObject * Boolean_tp_repr(PyObject *self) { @@ -122,7 +128,7 @@ PyTypeObject DBusPyBoolean_Type = { 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + Boolean_tp_str, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ -- cgit v1.2.1