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

Skip to content

Commit 3b09cd6

Browse files
committed
Merge
2 parents 25d94bb + f0f1c23 commit 3b09cd6

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lib/test/test_builtin.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import ast
44
import builtins
55
import collections
6+
import decimal
7+
import fractions
68
import io
79
import locale
810
import os
@@ -1244,6 +1246,15 @@ def test_round_large(self):
12441246
self.assertEqual(round(5e15+2), 5e15+2)
12451247
self.assertEqual(round(5e15+3), 5e15+3)
12461248

1249+
def test_bug_27936(self):
1250+
# Verify that ndigits=None means the same as passing in no argument
1251+
for x in [1234,
1252+
1234.56,
1253+
decimal.Decimal('1234.56'),
1254+
fractions.Fraction(123456, 100)]:
1255+
self.assertEqual(round(x, None), round(x))
1256+
self.assertEqual(type(round(x, None)), type(round(x)))
1257+
12471258
def test_setattr(self):
12481259
setattr(sys, 'spam', 1)
12491260
self.assertEqual(sys.spam, 1)

Lib/test/test_long.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ def test_round(self):
10151015
self.assertIs(type(got), int)
10161016

10171017
# bad second argument
1018-
bad_exponents = ('brian', 2.0, 0j, None)
1018+
bad_exponents = ('brian', 2.0, 0j)
10191019
for e in bad_exponents:
10201020
self.assertRaises(TypeError, round, 3, e)
10211021

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ Core and Builtins
4646
``m_methods`` field to be used to add module level functions to instances
4747
of non-module types returned from ``Py_create_mod``. Patch by Xiang Zhang.
4848

49+
- Issue #27936: The round() function accepted a second None argument
50+
for some types but not for others. Fixed the inconsistency by
51+
accepting None for all numeric types.
52+
4953
- Issue #27487: Warn if a submodule argument to "python -m" or
5054
runpy.run_module() is found in sys.modules after parent packages are
5155
imported, but before the submodule is executed.

Python/bltinmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
20432043
return NULL;
20442044
}
20452045

2046-
if (ndigits == NULL)
2046+
if (ndigits == NULL || ndigits == Py_None)
20472047
result = PyObject_CallFunctionObjArgs(round, NULL);
20482048
else
20492049
result = PyObject_CallFunctionObjArgs(round, ndigits, NULL);

0 commit comments

Comments
 (0)