Skip to content

Commit

Permalink
pythongh-94808: Add coverage test for number check (pythongh-111445)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohilas authored and Glyphack committed Jan 27, 2024
1 parent 6e2c6c8 commit af287e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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
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()
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

0 comments on commit af287e6

Please sign in to comment.