[issue27934] json float encoding incorrect for dbus.Double
Changes by Eddie James <eaja...@us.ibm.com>: Added file: http://bugs.python.org/file44349/json-float-repr-2.7.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
Eddie James added the comment: Python 2.7 also already behaves correctly for other dbus types: Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dbus >>> import json >>> x = dbus.Int32(3) >>> x dbus.Int32(3) >>> json.dumps(x) '3' >>> repr(x) 'dbus.Int32(3)' -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
Eddie James added the comment: Wait what about the json C code for 2.7? That's still using PyObject_Repr() which will call tp_repr for dbus.Double... Any suggestions? -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
Eddie James added the comment: Thanks Mark, yes you installed the right package. OK I didn't dig deep enough in the sub class. And yea, there shouldn't be any difference between float.__repr__ and float.__str__. Obviously repr calls the object's tp_repr method, while float.__repr__ calls the base float method, which is the one we want. I didn't do any testing for python 3.x as I couldn't figure out how to import dbus into a local build of 3.x. My mistake here. > For 2.7, we may want to consider processing float instances using > `float.__repr__` instead of plain old `repr` That should work! I'll upload a new patch for 2.7 -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
Eddie James added the comment: Understood on 2.7, I wasn't aware it would cause any issues. Dbus.Double is not a subclass of float unfortunately. Problem is that all Dbus types seem to have a custom tp_repr method that returns that strange formatting I mentioned. So repr won't be the same as str, in any version of python. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
Changes by Eddie James <eaja...@us.ibm.com>: Added file: http://bugs.python.org/file44334/json-float-str-2.7.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27934] json float encoding incorrect for dbus.Double
New submission from Eddie James: JSON does not correctly encode dbus.Double types, even though all other dbus types are handled fine. I end up with output like this (0.25 is the floating point value): dbus.Double(0.25, variant_level=1) Found that the encoding uses repr() for float objects but uses str() for integer objects. I propose a change to use str() for float objects as well. This could be ported back to 2.7 as well -- components: Library (Lib) files: json-float-str-default.patch keywords: patch messages: 274179 nosy: eajames priority: normal severity: normal status: open title: json float encoding incorrect for dbus.Double type: behavior versions: Python 2.7, Python 3.6 Added file: http://bugs.python.org/file44333/json-float-str-default.patch ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue27934> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com