diff --git a/Lib/test/test_capi/test_abstract.py b/Lib/test/test_capi/test_abstract.py index eeaef60a8b4..687ce1e6376 100644 --- a/Lib/test/test_capi/test_abstract.py +++ b/Lib/test/test_capi/test_abstract.py @@ -817,6 +817,13 @@ class CAPITest(unittest.TestCase): self.assertRaises(TypeError, xtuple, 42) self.assertRaises(SystemError, xtuple, NULL) + def test_number_check(self): + number_check = _testcapi.number_check + self.assertTrue(number_check(1 + 1j)) + self.assertTrue(number_check(1)) + self.assertTrue(number_check(0.5)) + self.assertFalse(number_check("1 + 1j")) + if __name__ == "__main__": unittest.main() diff --git a/Modules/_testcapi/abstract.c b/Modules/_testcapi/abstract.c index a93477a7090..4a9144e66f0 100644 --- a/Modules/_testcapi/abstract.c +++ b/Modules/_testcapi/abstract.c @@ -180,6 +180,12 @@ object_delattrstring(PyObject *self, PyObject *args) RETURN_INT(PyObject_DelAttrString(obj, attr_name)); } +static PyObject * +number_check(PyObject *self, PyObject *obj) +{ + NULLABLE(obj); + return PyBool_FromLong(PyNumber_Check(obj)); +} static PyObject * mapping_check(PyObject *self, PyObject *obj) @@ -623,6 +629,7 @@ static PyMethodDef test_methods[] = { {"object_delattr", object_delattr, METH_VARARGS}, {"object_delattrstring", object_delattrstring, METH_VARARGS}, + {"number_check", number_check, METH_O}, {"mapping_check", mapping_check, METH_O}, {"mapping_size", mapping_size, METH_O}, {"mapping_length", mapping_length, METH_O},