summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2016-09-03 08:55:39 (GMT)
committerRaymond Hettinger <python@rcn.com>2016-09-03 08:55:39 (GMT)
commit3b09cd64e0a7991bcb6d3f83a0a23be2fc81213f (patch)
treec6111132a4ec6fe8f29abd76e882c58442a3d57c
parent25d94bbf05f37151e7e6e3a2e1cd5af4a3e5f68c (diff)
parentf0f1c239e4addd15180d605306a969a627cb19d5 (diff)
downloadcpython-3b09cd64e0a7991bcb6d3f83a0a23be2fc81213f.zip
cpython-3b09cd64e0a7991bcb6d3f83a0a23be2fc81213f.tar.gz
cpython-3b09cd64e0a7991bcb6d3f83a0a23be2fc81213f.tar.bz2
Merge
-rw-r--r--Lib/test/test_builtin.py11
-rw-r--r--Lib/test/test_long.py2
-rw-r--r--Misc/NEWS4
-rw-r--r--Python/bltinmodule.c2
4 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index acc4f9c..7741a79 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -3,6 +3,8 @@
import ast
import builtins
import collections
+import decimal
+import fractions
import io
import locale
import os
@@ -1244,6 +1246,15 @@ class BuiltinTest(unittest.TestCase):
self.assertEqual(round(5e15+2), 5e15+2)
self.assertEqual(round(5e15+3), 5e15+3)
+ def test_bug_27936(self):
+ # Verify that ndigits=None means the same as passing in no argument
+ for x in [1234,
+ 1234.56,
+ decimal.Decimal('1234.56'),
+ fractions.Fraction(123456, 100)]:
+ self.assertEqual(round(x, None), round(x))
+ self.assertEqual(type(round(x, None)), type(round(x)))
+
def test_setattr(self):
setattr(sys, 'spam', 1)
self.assertEqual(sys.spam, 1)
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index 4d293f2..4cc4b05 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -1015,7 +1015,7 @@ class LongTest(unittest.TestCase):
self.assertIs(type(got), int)
# bad second argument
- bad_exponents = ('brian', 2.0, 0j, None)
+ bad_exponents = ('brian', 2.0, 0j)
for e in bad_exponents:
self.assertRaises(TypeError, round, 3, e)
diff --git a/Misc/NEWS b/Misc/NEWS
index be46c6b..5c07791 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,10 @@ Core and Builtins
``m_methods`` field to be used to add module level functions to instances
of non-module types returned from ``Py_create_mod``. Patch by Xiang Zhang.
+- Issue #27936: The round() function accepted a second None argument
+ for some types but not for others. Fixed the inconsistency by
+ accepting None for all numeric types.
+
- Issue #27487: Warn if a submodule argument to "python -m" or
runpy.run_module() is found in sys.modules after parent packages are
imported, but before the submodule is executed.
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index a1cd978..dc2daa8 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2043,7 +2043,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
return NULL;
}
- if (ndigits == NULL)
+ if (ndigits == NULL || ndigits == Py_None)
result = PyObject_CallFunctionObjArgs(round, NULL);
else
result = PyObject_CallFunctionObjArgs(round, ndigits, NULL);