Message274226
> I propose a change to use str() for float objects as well. This could be ported back to 2.7 as well
That would be a behaviour change for 2.7, and an undesirable one. `str` loses precision in Python 2, so e.g., `json.loads(json.dumps(pi)) == pi` would no longer be true. (Indeed, the json library was changed to use `repr` rather than `str` for floats at some point in the past, for exactly this reason.)
I assume that dbus.Double is a subclass of float. Is that correct? If that's the case, I'm a bit confused: `float.__repr__` behaves identically to `float.__str__` in Python versions >= 3.2, so I don't see what your suggested change would achieve.
>>> class MyFloat(float):
... def __repr__(self): return "MyFloat(something_or_other)"
... def __str__(self): return "1729.0"
...
>>> x = MyFloat(2.3)
>>> import json
>>> json.dumps(x)
'2.3' |
|
Date |
User |
Action |
Args |
2016-09-02 10:42:48 | mark.dickinson | set | recipients:
+ mark.dickinson, eajames |
2016-09-02 10:42:48 | mark.dickinson | set | messageid: <1472812968.08.0.712438118279.issue27934@psf.upfronthosting.co.za> |
2016-09-02 10:42:48 | mark.dickinson | link | issue27934 messages |
2016-09-02 10:42:47 | mark.dickinson | create | |
|