More bug 460020: when F is a subclass of float, disable the unary plus
optimization (+F(whatever)).
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index e89f642..a50785f 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1401,6 +1401,7 @@
a = precfloat(12345)
verify(float(a) == 12345.0)
verify(float(a).__class__ is float)
+ verify((+a).__class__ is float)
class madtuple(tuple):
_rev = None
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d606547..880eb0e 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -553,8 +553,12 @@
static PyObject *
float_pos(PyFloatObject *v)
{
- Py_INCREF(v);
- return (PyObject *)v;
+ if (PyFloat_CheckExact(v)) {
+ Py_INCREF(v);
+ return (PyObject *)v;
+ }
+ else
+ return PyFloat_FromDouble(v->ob_fval);
}
static PyObject *