mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-100268: Add is_integer method to int (#100439)
This improves the lives of type annotation users of `float` - which type checkers implicitly treat as `int|float` because that is what most code actually wants. Before this change a `.is_integer()` method could not be assumed to exist on things annotated as `: float` due to the method not existing on both types.
This commit is contained in:
parent
a23cb72ac8
commit
3e46f9fe05
5 changed files with 45 additions and 1 deletions
|
@ -6168,6 +6168,19 @@ long_long_meth(PyObject *self, PyObject *Py_UNUSED(ignored))
|
|||
return long_long(self);
|
||||
}
|
||||
|
||||
/*[clinic input]
|
||||
int.is_integer
|
||||
|
||||
Returns True. Exists for duck type compatibility with float.is_integer.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
int_is_integer_impl(PyObject *self)
|
||||
/*[clinic end generated code: output=90f8e794ce5430ef input=7e41c4d4416e05f2]*/
|
||||
{
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
static PyMethodDef long_methods[] = {
|
||||
{"conjugate", long_long_meth, METH_NOARGS,
|
||||
"Returns self, the complex conjugate of any int."},
|
||||
|
@ -6186,6 +6199,7 @@ static PyMethodDef long_methods[] = {
|
|||
INT___GETNEWARGS___METHODDEF
|
||||
INT___FORMAT___METHODDEF
|
||||
INT___SIZEOF___METHODDEF
|
||||
INT_IS_INTEGER_METHODDEF
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue