summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-11 21:53:35 +0000
committerTim Peters <tim.peters@gmail.com>2001-09-11 21:53:35 +0000
commit0280cf79a71cf2bf710d57e921d61184aa1b2dfd (patch)
treec5dd1d437398d512b4be1cb0cc8724733656286c
parent73a1dfe3674429f923e98b84ef01df1614baad2f (diff)
downloadcpython-git-0280cf79a71cf2bf710d57e921d61184aa1b2dfd.tar.gz
More bug 460020: when F is a subclass of float, disable the unary plus
optimization (+F(whatever)).
-rw-r--r--Lib/test/test_descr.py1
-rw-r--r--Objects/floatobject.c8
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index e89f6425b9..a50785f58a 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1401,6 +1401,7 @@ def inherits():
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 d606547841..880eb0e1e0 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -553,8 +553,12 @@ float_neg(PyFloatObject *v)
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 *