Kaydet (Commit) 7a50f253 authored tarafından Tim Peters's avatar Tim Peters

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.
üst c6249e9f
......@@ -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
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment