diff options
author | Simon McVittie <smcv@collabora.com> | 2019-11-21 09:37:00 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2019-11-21 09:46:43 +0000 |
commit | 4dd9506dcca181b8b44963fbdccb1e3db8ea7938 (patch) | |
tree | 0d59de2c8104e830ff6b5341ef7834abe3044652 | |
parent | 1f7002d8a2f4c7cfba9f10e1d771812dd91977b6 (diff) | |
download | dbus-python-4dd9506dcca181b8b44963fbdccb1e3db8ea7938.tar.gz |
abstract: Stringify float subclasses using float's repr
Python 3.8 removes the tp_str for various built-in types, so we would
print Double values as their repr (for example dbus.Double(0.5)), which
is a regression. Print them as 0.5 instead.
Signed-off-by: Simon McVittie <smcv@collabora.com>
-rw-r--r-- | dbus_bindings/abstract.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/dbus_bindings/abstract.c b/dbus_bindings/abstract.c index 6123c3d..4eca52a 100644 --- a/dbus_bindings/abstract.c +++ b/dbus_bindings/abstract.c @@ -287,6 +287,19 @@ PyTypeObject DBusPyIntBase_Type = { /* There's only one subclass at the moment (Double) but these are factored out to make room for Float later. (Float is implemented and #if'd out) */ +#ifdef PY3 +/* In Python >= 3.8 the tp_str for subclasses of built-in types prints + * the subclass repr(), which does not match dbus-python's historical + * behaviour. */ +static PyObject * +DBusPythonFloat_tp_str(PyObject *self) +{ + return (PyFloat_Type.tp_repr)(self); +} +#else +#define DBusPythonFloat_tp_str 0 +#endif + PyDoc_STRVAR(DBusPythonFloat_tp_doc,\ "Base class for float subclasses with a ``variant_level`` attribute.\n" "Do not rely on the existence of this class outside dbus-python.\n" @@ -367,7 +380,7 @@ PyTypeObject DBusPyFloatBase_Type = { 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ - 0, /* tp_str */ + DBusPythonFloat_tp_str, /* tp_str */ 0, /* tp_getattro */ 0, /* tp_setattro */ 0, /* tp_as_buffer */ |