diff options
author | Simon McVittie <smcv@collabora.com> | 2019-11-21 09:26:41 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2019-11-21 09:46:43 +0000 |
commit | 1f7002d8a2f4c7cfba9f10e1d771812dd91977b6 (patch) | |
tree | 68603532ab48c987f7db279f1340871575c27068 | |
parent | 1537eef58ed5b0b79f97407db8387f1c1ed63887 (diff) | |
download | dbus-python-1f7002d8a2f4c7cfba9f10e1d771812dd91977b6.tar.gz |
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 <smcv@collabora.com>
-rw-r--r-- | dbus_bindings/int.c | 8 |
1 files changed, 7 insertions, 1 deletions
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 @@ -81,6 +81,12 @@ Boolean_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) } static PyObject * +Boolean_tp_str(PyObject *self) +{ + return PyUnicode_FromString(PyObject_IsTrue(self) ? "1" : "0"); +} + +static PyObject * Boolean_tp_repr(PyObject *self) { int is_true = PyObject_IsTrue(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 */ |