summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-10 21:28:20 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-10 21:28:20 (GMT)
commit7a50f2536e59762897a05b1d3996e51f3f1a9686 (patch)
treef4108edcb9db12a21759f9ed10c30c28c2ca5340
parentc6249e9fef66057a1f89b8d4d6bcd5c0e1cfc217 (diff)
downloadcpython-7a50f2536e59762897a05b1d3996e51f3f1a9686.zip
cpython-7a50f2536e59762897a05b1d3996e51f3f1a9686.tar.gz
cpython-7a50f2536e59762897a05b1d3996e51f3f1a9686.tar.bz2
More for SF bug [#460020] bug or feature: unicode() and subclasses
Repair float constructor to return a true float when passed a subclass instance. New PyFloat_CheckExact macro.
-rw-r--r--Include/floatobject.h1
-rw-r--r--Lib/test/test_descr.py2
-rw-r--r--Objects/abstract.c6
3 files changed, 7 insertions, 2 deletions
diff --git a/Include/floatobject.h b/Include/floatobject.h
index 9f67bc1..bd4a782 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -19,6 +19,7 @@ typedef struct {
extern DL_IMPORT(PyTypeObject) PyFloat_Type;
#define PyFloat_Check(op) PyObject_TypeCheck(op, &PyFloat_Type)
+#define PyFloat_CheckExact(op) ((op)->ob_type == &PyFloat_Type)
/* Return Python float from string PyObject. Second argument ignored on
input, and, if non-NULL, NULL is stored into *junk (this tried to serve a
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 35544c6..1ff9060 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1372,7 +1372,7 @@ def inherits():
verify(repr(precfloat(1.1)) == "1.1")
a = precfloat(12345)
#XXX verify(float(a) == 12345.0)
- #XXX verify(float(a).__class__ is float)
+ verify(float(a).__class__ is float)
class madtuple(tuple):
_rev = None
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 2bd0fcc..37f7eea 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -909,10 +909,14 @@ PyNumber_Float(PyObject *o)
if (o == NULL)
return null_error();
- if (PyFloat_Check(o)) {
+ if (PyFloat_CheckExact(o)) {
Py_INCREF(o);
return o;
}
+ if (PyFloat_Check(o)) {
+ PyFloatObject *po = (PyFloatObject *)o;
+ return PyFloat_FromDouble(po->ob_fval);
+ }
if (!PyString_Check(o)) {
m = o->ob_type->tp_as_number;
if (m && m->nb_float)