summaryrefslogtreecommitdiffstats
path: root/Objects/clinic/longobject.c.h
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2022-12-24 02:30:27 (GMT)
committerGitHub <noreply@github.com>2022-12-24 02:30:27 (GMT)
commit3e46f9fe05b40ee42009878620f448d3a4b44cb5 (patch)
tree73a990d85dd392b93303c8fe98276029eef15f5b /Objects/clinic/longobject.c.h
parenta23cb72ac82372fac05ba36ce08923840ca0de06 (diff)
downloadcpython-3e46f9fe05b40ee42009878620f448d3a4b44cb5.zip
cpython-3e46f9fe05b40ee42009878620f448d3a4b44cb5.tar.gz
cpython-3e46f9fe05b40ee42009878620f448d3a4b44cb5.tar.bz2
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.
Diffstat (limited to 'Objects/clinic/longobject.c.h')
-rw-r--r--Objects/clinic/longobject.c.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h
index dde4909..206bffd 100644
--- a/Objects/clinic/longobject.c.h
+++ b/Objects/clinic/longobject.c.h
@@ -467,4 +467,22 @@ skip_optional_kwonly:
exit:
return return_value;
}
-/*[clinic end generated code: output=bf6074ecf2f32cf4 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(int_is_integer__doc__,
+"is_integer($self, /)\n"
+"--\n"
+"\n"
+"Returns True. Exists for duck type compatibility with float.is_integer.");
+
+#define INT_IS_INTEGER_METHODDEF \
+ {"is_integer", (PyCFunction)int_is_integer, METH_NOARGS, int_is_integer__doc__},
+
+static PyObject *
+int_is_integer_impl(PyObject *self);
+
+static PyObject *
+int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
+{
+ return int_is_integer_impl(self);
+}
+/*[clinic end generated code: output=e518fe2b5d519322 input=a9049054013a1b77]*/