cpython: 050e5f803999 (original) (raw)

Mercurial > cpython

changeset 101661:050e5f803999

Issue #26983: float() now always return an instance of exact float. The deprecation warning is emitted if __float__ returns an instance of a strict subclass of float. In a future versions of Python this can be an error. [#26983]

Serhiy Storchaka storchaka@gmail.com
date Fri, 03 Jun 2016 21:42:55 +0300
parents 19488e23dcdb
children 365b5e6163a6
files Lib/test/test_float.py Lib/test/test_getargs2.py Misc/NEWS Objects/abstract.c Objects/floatobject.c
diffstat 5 files changed, 76 insertions(+), 32 deletions(-)[+] [-] Lib/test/test_float.py 21 Lib/test/test_getargs2.py 6 Misc/NEWS 5 Objects/abstract.c 30 Objects/floatobject.c 46

line wrap: on

line diff

--- a/Lib/test/test_float.py +++ b/Lib/test/test_float.py @@ -161,11 +161,12 @@ class GeneralFloatCases(unittest.TestCas def float(self): return float(str(self)) + 1

class Foo5: def float(self): @@ -176,10 +177,14 @@ class GeneralFloatCases(unittest.TestCas class F: def float(self): return OtherFloatSubclass(42.)

def test_is_integer(self): self.assertFalse((1.1).is_integer())

--- a/Lib/test/test_getargs2.py +++ b/Lib/test/test_getargs2.py @@ -365,7 +365,8 @@ class Float_TestCase(unittest.TestCase): self.assertEqual(getargs_f(FloatSubclass(7.5)), 7.5) self.assertEqual(getargs_f(FloatSubclass2(7.5)), 7.5) self.assertRaises(TypeError, getargs_f, BadFloat())

for x in (FLT_MIN, -FLT_MIN, FLT_MAX, -FLT_MAX, INF, -INF): @@ -390,7 +391,8 @@ class Float_TestCase(unittest.TestCase): self.assertEqual(getargs_d(FloatSubclass(7.5)), 7.5) self.assertEqual(getargs_d(FloatSubclass2(7.5)), 7.5) self.assertRaises(TypeError, getargs_d, BadFloat())

for x in (DBL_MIN, -DBL_MIN, DBL_MAX, -DBL_MAX, INF, -INF):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,11 @@ What's New in Python 3.6.0 alpha 2 Core and Builtins ----------------- +- Issue #26983: float() now always return an instance of exact float.

--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1351,21 +1351,39 @@ PyNumber_Float(PyObject *o) if (o == NULL) return null_error();

--- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -215,35 +215,49 @@ double PyFloat_AsDouble(PyObject *op) { PyNumberMethods *nb;

- if (op == NULL) { PyErr_BadArgument(); return -1; }

+

-