Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-26680: Adds support for int.is_integer() for compatibility with f…
…loat.is_integer().

The int.is_integer() method always returns True.
  • Loading branch information
rob-smallshire committed Sep 18, 2020
commit d80b01737c4691b3d42f49b3852913c21d1c1e8f
4 changes: 4 additions & 0 deletions Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,10 @@ class myint(int):
self.assertEqual(type(numerator), int)
self.assertEqual(type(denominator), int)

def test_int_always_is_integer(self):
# Issue #26680: Incorporating number.is_integer into int
self.assertTrue(all(x.is_integer() for x in (-1, 0, 1, 42)))


if __name__ == "__main__":
unittest.main()
20 changes: 19 additions & 1 deletion Objects/clinic/longobject.c.h

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

14 changes: 14 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5233,6 +5233,19 @@ int___round___impl(PyObject *self, PyObject *o_ndigits)
return result;
}

/*[clinic input]
int.is_integer

Returns True for all integers.
[clinic start generated code]*/

static PyObject *
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we convert this to Argument Clinic? It seems somewhat trivial, but one advantage is having the docstring close to the definition. Another is having docstring consistency between int.is_integer and float.is_integer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

int_is_integer_impl(PyObject *self)
/*[clinic end generated code: output=90f8e794ce5430ef input=903121d57b734c35]*/
{
Py_RETURN_TRUE;
}

/*[clinic input]
int.__sizeof__ -> Py_ssize_t

Expand Down Expand Up @@ -5547,6 +5560,7 @@ static PyMethodDef long_methods[] = {
{"__ceil__", long_long_meth, METH_NOARGS,
"Ceiling of an Integral returns itself."},
INT___ROUND___METHODDEF
INT_IS_INTEGER_METHODDEF
INT___GETNEWARGS___METHODDEF
INT___FORMAT___METHODDEF
INT___SIZEOF___METHODDEF
Expand Down