self.assertEqual(x, 2)
self.assertIsInstance(x, int)
+ def test_round_with_none_arg_direct_call(self):
+ for val in [(1.0).__round__(None),
+ round(1.0),
+ round(1.0, None)]:
+ self.assertEqual(val, 1)
+ self.assertIs(type(val), int)
# Beginning with Python 2.6 float has cross platform compatible
# ways to create and represent inf and nan
'bytearray': {'count', 'endswith', 'find', 'hex', 'index', 'rfind', 'rindex', 'startswith'},
'bytes': {'count', 'endswith', 'find', 'hex', 'index', 'rfind', 'rindex', 'startswith'},
'dict': {'pop'},
- 'int': {'__round__'},
'memoryview': {'cast', 'hex'},
'str': {'count', 'endswith', 'find', 'index', 'maketrans', 'rfind', 'rindex', 'startswith'},
}
self.assertEqual(int('1_2_3_4_5_6_7_8_9', 16), 0x123456789)
self.assertEqual(int('1_2_3_4_5_6_7', 32), 1144132807)
+ def test_round_with_none_arg_direct_call(self):
+ for val in [(1).__round__(None),
+ round(1),
+ round(1, None)]:
+ self.assertEqual(val, 1)
+ self.assertIs(type(val), int)
class IntStrDigitLimitsTests(unittest.TestCase):
--- /dev/null
+Direct call to the :meth:`!int.__round__` now accepts ``None``
+as a valid argument.
}
PyDoc_STRVAR(int___round____doc__,
-"__round__($self, ndigits=<unrepresentable>, /)\n"
+"__round__($self, ndigits=None, /)\n"
"--\n"
"\n"
"Rounding an Integral returns itself.\n"
int___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
{
PyObject *return_value = NULL;
- PyObject *o_ndigits = NULL;
+ PyObject *o_ndigits = Py_None;
if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
goto exit;
{
return int_is_integer_impl(self);
}
-/*[clinic end generated code: output=2ba2d8dcda9b99da input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a53f5ba9a6c16737 input=a9049054013a1b77]*/
/*[clinic input]
int.__round__
- ndigits as o_ndigits: object = NULL
+ ndigits as o_ndigits: object = None
/
Rounding an Integral returns itself.
static PyObject *
int___round___impl(PyObject *self, PyObject *o_ndigits)
-/*[clinic end generated code: output=954fda6b18875998 input=1614cf23ec9e18c3]*/
+/*[clinic end generated code: output=954fda6b18875998 input=30c2aec788263144]*/
{
PyObject *temp, *result, *ndigits;
*
* m - divmod_near(m, 10**n)[1].
*/
- if (o_ndigits == NULL)
+ if (o_ndigits == Py_None)
return long_long(self);
ndigits = _PyNumber_Index(o_ndigits);