Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-115015: Argument Clinic: fix generated code for METH_METHOD methods without args #115016

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

Merged
merged 12 commits into from
Feb 5, 2024
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
4 changes: 2 additions & 2 deletions Lib/test/clinic.test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4625,7 +4625,7 @@ Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls);
static PyObject *
Test_cls_no_params(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
{
if (nargs) {
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
PyErr_SetString(PyExc_TypeError, "cls_no_params() takes no arguments");
return NULL;
}
Expand All @@ -4634,7 +4634,7 @@ Test_cls_no_params(TestObj *self, PyTypeObject *cls, PyObject *const *args, Py_s

static PyObject *
Test_cls_no_params_impl(TestObj *self, PyTypeObject *cls)
/*[clinic end generated code: output=cc8845f22cff3dcb input=e7e2e4e344e96a11]*/
/*[clinic end generated code: output=4d68b4652c144af3 input=e7e2e4e344e96a11]*/


/*[clinic input]
Expand Down
20 changes: 20 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3288,6 +3288,26 @@ def test_cloned_func_with_converter_exception_message(self):
func = getattr(ac_tester, name)
self.assertEqual(func(), name)

def test_meth_method_no_params(self):
obj = ac_tester.TestClass()
meth = obj.meth_method_no_params
check = partial(self.assertRaisesRegex, TypeError, "no arguments")
check(meth, 1)
check(meth, a=1)

def test_meth_method_no_params_capi(self):
from _testcapi import pyobject_vectorcall
obj = ac_tester.TestClass()
meth = obj.meth_method_no_params
pyobject_vectorcall(meth, None, None)
pyobject_vectorcall(meth, (), None)
pyobject_vectorcall(meth, (), ())
pyobject_vectorcall(meth, None, ())

check = partial(self.assertRaisesRegex, TypeError, "no arguments")
check(pyobject_vectorcall, meth, (1,), None)
check(pyobject_vectorcall, meth, (1,), ("a",))

def test_depr_star_new(self):
cls = ac_tester.DeprStarNew
cls()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fix a bug in Argument Clinic that generated incorrect code for methods with
no parameters that use the :ref:`METH_METHOD | METH_FASTCALL | METH_KEYWORDS
<METH_METHOD-METH_FASTCALL-METH_KEYWORDS>` calling convention. Only the
positional parameter count was checked; any keyword argument passed would be
silently accepted.
4 changes: 2 additions & 2 deletions Modules/_io/clinic/bufferedio.c.h

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

4 changes: 2 additions & 2 deletions Modules/_io/clinic/bytesio.c.h

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

4 changes: 2 additions & 2 deletions Modules/_io/clinic/fileio.c.h

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

4 changes: 2 additions & 2 deletions Modules/_io/clinic/iobase.c.h

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

4 changes: 2 additions & 2 deletions Modules/_io/clinic/textio.c.h

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

4 changes: 2 additions & 2 deletions Modules/_io/clinic/winconsoleio.c.h

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

6 changes: 3 additions & 3 deletions Modules/_sre/clinic/sre.c.h

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

37 changes: 37 additions & 0 deletions Modules/_testclinic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,40 @@ clone_with_conv_f2_impl(PyObject *module, custom_t path)
}


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

/*[clinic input]
_testclinic.TestClass.meth_method_no_params
cls: defining_class
/
[clinic start generated code]*/

static PyObject *
_testclinic_TestClass_meth_method_no_params_impl(PyObject *self,
PyTypeObject *cls)
/*[clinic end generated code: output=c140f100080c2fc8 input=6bd34503d11c63c1]*/
{
Py_RETURN_NONE;
}

static struct PyMethodDef test_class_methods[] = {
_TESTCLINIC_TESTCLASS_METH_METHOD_NO_PARAMS_METHODDEF
{NULL, NULL}
};

static PyTypeObject TestClass = {
PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "_testclinic.TestClass",
.tp_basicsize = sizeof(PyObject),
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericNew,
.tp_methods = test_class_methods,
};


/*[clinic input]
output push
destination deprstar new file '{dirname}/clinic/_testclinic_depr.c.h'
Expand Down Expand Up @@ -1906,6 +1940,9 @@ PyInit__testclinic(void)
if (m == NULL) {
return NULL;
}
if (PyModule_AddType(m, &TestClass) < 0) {
goto error;
}
if (PyModule_AddType(m, &DeprStarNew) < 0) {
goto error;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/cjkcodecs/clinic/multibytecodec.c.h

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

6 changes: 3 additions & 3 deletions Modules/clinic/_asynciomodule.c.h

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

12 changes: 6 additions & 6 deletions Modules/clinic/_curses_panel.c.h

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

6 changes: 3 additions & 3 deletions Modules/clinic/_dbmmodule.c.h

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

6 changes: 3 additions & 3 deletions Modules/clinic/_elementtree.c.h

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

Loading