Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0280cf7

Browse files
committed
More bug 460020: when F is a subclass of float, disable the unary plus
optimization (+F(whatever)).
1 parent 73a1dfe commit 0280cf7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Lib/test/test_descr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ def __repr__(self):
14011401
a = precfloat(12345)
14021402
verify(float(a) == 12345.0)
14031403
verify(float(a).__class__ is float)
1404+
verify((+a).__class__ is float)
14041405

14051406
class madtuple(tuple):
14061407
_rev = None

Objects/floatobject.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,12 @@ float_neg(PyFloatObject *v)
553553
static PyObject *
554554
float_pos(PyFloatObject *v)
555555
{
556-
Py_INCREF(v);
557-
return (PyObject *)v;
556+
if (PyFloat_CheckExact(v)) {
557+
Py_INCREF(v);
558+
return (PyObject *)v;
559+
}
560+
else
561+
return PyFloat_FromDouble(v->ob_fval);
558562
}
559563

560564
static PyObject *

0 commit comments

Comments
 (0)