Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-94808: Add coverage test for number check #111445

Merged
merged 5 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions Lib/test/test_capi/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,13 @@ def test_sequence_tuple(self):
self.assertRaises(TypeError, xtuple, 42)
self.assertRaises(SystemError, xtuple, NULL)

def test_number_check(self):
number_check = _testcapi.number_check
ekohilas marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(number_check(1 + 1j))
ekohilas marked this conversation as resolved.
Show resolved Hide resolved
self.assertTrue(number_check(1))
self.assertTrue(number_check(0.5))
self.assertFalse(number_check("1 + 1j"))


if __name__ == "__main__":
unittest.main()
7 changes: 7 additions & 0 deletions Modules/_testcapi/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
Expand Down