Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests for no-fastcall.
  • Loading branch information
serhiy-storchaka committed Nov 6, 2024
commit cb835fece45a3471bbeb95ae9b082b188bbd854c
35 changes: 35 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3384,6 +3384,12 @@ def test_varpos(self):
self.assertEqual(fn(), ())
self.assertEqual(fn(1, 2), (1, 2))

def test_varpos_no_fastcall(self):
# fn(*args), no fastcall
fn = ac_tester.TestClass.varpos_no_fastcall
self.assertEqual(fn(), ())
self.assertEqual(fn(1, 2), (1, 2))

def test_posonly_varpos(self):
# fn(a, b, /, *args)
fn = ac_tester.posonly_varpos
Expand All @@ -3393,6 +3399,15 @@ def test_posonly_varpos(self):
self.assertEqual(fn(1, 2), (1, 2, ()))
self.assertEqual(fn(1, 2, 3, 4), (1, 2, (3, 4)))

def test_posonly_varpos_no_fastcall(self):
# fn(a, b, /, *args), no fastcall
fn = ac_tester.TestClass.posonly_varpos_no_fastcall
self.assertRaises(TypeError, fn)
self.assertRaises(TypeError, fn, 1)
self.assertRaises(TypeError, fn, 1, b=2)
self.assertEqual(fn(1, 2), (1, 2, ()))
self.assertEqual(fn(1, 2, 3, 4), (1, 2, (3, 4)))

def test_posonly_req_opt_varpos(self):
# fn(a, b=False, /, *args)
fn = ac_tester.posonly_req_opt_varpos
Expand All @@ -3402,6 +3417,15 @@ def test_posonly_req_opt_varpos(self):
self.assertEqual(fn(1, 2), (1, 2, ()))
self.assertEqual(fn(1, 2, 3, 4), (1, 2, (3, 4)))

def test_posonly_req_opt_varpos_no_fastcall(self):
# fn(a, b=False, /, *args), no fastcall
fn = ac_tester.TestClass.posonly_req_opt_varpos_no_fastcall
self.assertRaises(TypeError, fn)
self.assertRaises(TypeError, fn, a=1)
self.assertEqual(fn(1), (1, False, ()))
self.assertEqual(fn(1, 2), (1, 2, ()))
self.assertEqual(fn(1, 2, 3, 4), (1, 2, (3, 4)))

def test_posonly_poskw_varpos(self):
# fn(a, /, b, *args)
fn = ac_tester.posonly_poskw_varpos
Expand All @@ -3413,6 +3437,17 @@ def test_posonly_poskw_varpos(self):
errmsg = re.escape("given by name ('b') and position (2)")
self.assertRaisesRegex(TypeError, errmsg, fn, 1, 2, 3, b=4)

def test_posonly_poskw_varpos_no_fastcall(self):
# fn(a, /, b, *args), no fastcall
fn = ac_tester.TestClass.posonly_poskw_varpos_no_fastcall
self.assertRaises(TypeError, fn)
self.assertEqual(fn(1, 2), (1, 2, ()))
self.assertEqual(fn(1, b=2), (1, 2, ()))
self.assertEqual(fn(1, 2, 3, 4), (1, 2, (3, 4)))
self.assertRaises(TypeError, fn, b=4)
errmsg = re.escape("given by name ('b') and position (2)")
self.assertRaisesRegex(TypeError, errmsg, fn, 1, 2, 3, b=4)

def test_poskw_varpos(self):
# fn(a, *args)
fn = ac_tester.poskw_varpos
Expand Down
88 changes: 86 additions & 2 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,9 +1287,9 @@ clone_with_conv_f2_impl(PyObject *module, custom_t path)


/*[clinic input]
class _testclinic.TestClass "PyObject *" "PyObject"
class _testclinic.TestClass "PyObject *" "&PyBaseObject_Type"
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=668a591c65bec947]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=c991635bb3c91f1a]*/

/*[clinic input]
_testclinic.TestClass.get_defining_class
Expand Down Expand Up @@ -1352,11 +1352,95 @@ _testclinic_TestClass_defclass_posonly_varpos_impl(PyObject *self,
return pack_arguments_newref(4, cls, a, b, args);
}

/*[clinic input]
@classmethod
_testclinic.TestClass.__new__ as varpos_no_fastcall

*args: object

[clinic start generated code]*/

static PyObject *
varpos_no_fastcall_impl(PyTypeObject *type, PyObject *args)
/*[clinic end generated code: output=04e94f2898bb2dde input=b0447ebab3e81001]*/
{
return Py_NewRef(args);
}

/*[clinic input]
@classmethod
_testclinic.TestClass.__new__ as posonly_varpos_no_fastcall

a: object
b: object
/
*args: object

[clinic start generated code]*/

static PyObject *
posonly_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a, PyObject *b,
PyObject *args)
/*[clinic end generated code: output=b0a0425719f69f5a input=d2ec37a06b3c2389]*/
{
return pack_arguments_newref(3, a, b, args);
}


/*[clinic input]
@classmethod
_testclinic.TestClass.__new__ as posonly_req_opt_varpos_no_fastcall

a: object
b: object = False
/
*args: object

[clinic start generated code]*/

static PyObject *
posonly_req_opt_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
PyObject *b, PyObject *args)
/*[clinic end generated code: output=3c44915b1a554e2d input=e9e74686a5e6a06d]*/
{
return pack_arguments_newref(3, a, b, args);
}


/*[clinic input]
@classmethod
_testclinic.TestClass.__new__ as posonly_poskw_varpos_no_fastcall

a: object
/
b: object
*args: object

[clinic start generated code]*/

static PyObject *
posonly_poskw_varpos_no_fastcall_impl(PyTypeObject *type, PyObject *a,
PyObject *b, PyObject *args)
/*[clinic end generated code: output=6ad74bed4bdc7f96 input=fa931c38184213aa]*/
{
return pack_arguments_newref(3, a, b, args);
}

static struct PyMethodDef test_class_methods[] = {
_TESTCLINIC_TESTCLASS_GET_DEFINING_CLASS_METHODDEF
_TESTCLINIC_TESTCLASS_GET_DEFINING_CLASS_ARG_METHODDEF
_TESTCLINIC_TESTCLASS_DEFCLASS_VARPOS_METHODDEF
_TESTCLINIC_TESTCLASS_DEFCLASS_POSONLY_VARPOS_METHODDEF

{"varpos_no_fastcall", _PyCFunction_CAST(varpos_no_fastcall),
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
{"posonly_varpos_no_fastcall", _PyCFunction_CAST(posonly_varpos_no_fastcall),
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
{"posonly_req_opt_varpos_no_fastcall", _PyCFunction_CAST(posonly_req_opt_varpos_no_fastcall),
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},
{"posonly_poskw_varpos_no_fastcall", _PyCFunction_CAST(posonly_poskw_varpos_no_fastcall),
METH_VARARGS|METH_KEYWORDS|METH_CLASS, ""},

{NULL, NULL}
};

Expand Down
159 changes: 158 additions & 1 deletion Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.