This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients eajames, mark.dickinson
Date 2016-09-02.10:42:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472812968.08.0.712438118279.issue27934@psf.upfronthosting.co.za>
In-reply-to
Content
> 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'
History
Date User Action Args
2016-09-02 10:42:48mark.dickinsonsetrecipients: + mark.dickinson, eajames
2016-09-02 10:42:48mark.dickinsonsetmessageid: <1472812968.08.0.712438118279.issue27934@psf.upfronthosting.co.za>
2016-09-02 10:42:48mark.dickinsonlinkissue27934 messages
2016-09-02 10:42:47mark.dickinsoncreate