FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-120080: Accept ``None`` as a valid argument for direct call of the ``int.__round__`` (GH-120088) by miss-islington · Pull Request #120197 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (3) .rst  (1) All 4 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions Lib/test/test_float.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,12 @@ def test_None_ndigits(self):
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
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_inspect/test_inspect.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -5412,7 +5412,6 @@ def test_builtins_have_signatures(self):
'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'},
}
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_int.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,12 @@ def test_issue31619(self):
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):

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Direct call to the :meth:`!int.__round__` now accepts ``None``
as a valid argument.
6 changes: 3 additions & 3 deletions Objects/clinic/longobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Objects/longobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6034,7 +6034,7 @@ _PyLong_DivmodNear(PyObject *a, PyObject *b)
/*[clinic input]
int.__round__

ndigits as o_ndigits: object = NULL
ndigits as o_ndigits: object = None
/

Rounding an Integral returns itself.
Expand All @@ -6044,7 +6044,7 @@ Rounding with an ndigits argument also returns an integer.

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;

Expand All @@ -6062,7 +6062,7 @@ int___round___impl(PyObject *self, PyObject *o_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);
Expand Down

Back | FazBrowse Home | New Git URL