https://github.com/python/cpython/commit/ead9e784fb031429522bac6a43ddc0581458afd0
commit: ead9e784fb031429522bac6a43ddc0581458afd0
branch: 3.11
author: Erlend E. Aasland <[email protected]>
committer: erlend-aasland <[email protected]>
date: 2024-02-06T11:21:00+01:00
summary:

[3.11] gh-115015: Argument Clinic: fix generated code for METH_METHOD methods 
without params (#115016) (#115069)

(cherry picked from commit 09096a1647913526a3d4fa69a9d2056ec82a8f37)

files:
A Misc/NEWS.d/next/Tools-Demos/2024-02-05-02-45-51.gh-issue-115015.rgtiDB.rst
M Lib/test/clinic.test.c
M Lib/test/test_clinic.py
M Modules/_sre/clinic/sre.c.h
M Modules/_testclinic.c
M Modules/cjkcodecs/clinic/multibytecodec.c.h
M Modules/clinic/_curses_panel.c.h
M Modules/clinic/_dbmmodule.c.h
M Modules/clinic/_gdbmmodule.c.h
M Modules/clinic/_lsprof.c.h
M Modules/clinic/_queuemodule.c.h
M Modules/clinic/_testclinic.c.h
M Modules/clinic/_testmultiphase.c.h
M Modules/clinic/arraymodule.c.h
M Modules/clinic/md5module.c.h
M Modules/clinic/posixmodule.c.h
M Modules/clinic/sha1module.c.h
M Modules/clinic/sha256module.c.h
M Modules/clinic/sha512module.c.h
M Modules/clinic/zlibmodule.c.h
M Tools/c-analyzer/cpython/globals-to-fix.tsv
M Tools/clinic/clinic.py

diff --git a/Lib/test/clinic.test.c b/Lib/test/clinic.test.c
index feb30458b462ac..36f637918e6097 100644
--- a/Lib/test/clinic.test.c
+++ b/Lib/test/clinic.test.c
@@ -3891,7 +3891,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;
     }
@@ -3900,7 +3900,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]
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index bc0eee1552e46c..748a63e5348fce 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -2,6 +2,7 @@
 # Copyright 2012-2013 by Larry Hastings.
 # Licensed to the PSF under a contributor agreement.
 
+from functools import partial
 from test import support, test_tools
 from test.support import os_helper
 from test.support import SHORT_TIMEOUT, requires_subprocess
@@ -2032,6 +2033,26 @@ def test_gh_99240_double_free(self):
         with self.assertRaisesRegex(TypeError, expected_error):
             ac_tester.gh_99240_double_free('a', '\0b')
 
+    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",))
+
 
 class PermutationTests(unittest.TestCase):
     """Test permutation support functions."""
diff --git 
a/Misc/NEWS.d/next/Tools-Demos/2024-02-05-02-45-51.gh-issue-115015.rgtiDB.rst 
b/Misc/NEWS.d/next/Tools-Demos/2024-02-05-02-45-51.gh-issue-115015.rgtiDB.rst
new file mode 100644
index 00000000000000..d8739d28eb2b73
--- /dev/null
+++ 
b/Misc/NEWS.d/next/Tools-Demos/2024-02-05-02-45-51.gh-issue-115015.rgtiDB.rst
@@ -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.
diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h
index 048a494f1bc7c6..c63cdad9e38763 100644
--- a/Modules/_sre/clinic/sre.c.h
+++ b/Modules/_sre/clinic/sre.c.h
@@ -1089,7 +1089,7 @@ _sre_SRE_Scanner_match_impl(ScannerObject *self, 
PyTypeObject *cls);
 static PyObject *
 _sre_SRE_Scanner_match(ScannerObject *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, "match() takes no arguments");
         return NULL;
     }
@@ -1110,10 +1110,10 @@ _sre_SRE_Scanner_search_impl(ScannerObject *self, 
PyTypeObject *cls);
 static PyObject *
 _sre_SRE_Scanner_search(ScannerObject *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, "search() takes no arguments");
         return NULL;
     }
     return _sre_SRE_Scanner_search_impl(self, cls);
 }
-/*[clinic end generated code: output=fd2f45c941620e6e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=d4ed753aa4c9dc0a input=a9049054013a1b77]*/
diff --git a/Modules/_testclinic.c b/Modules/_testclinic.c
index 91fdee24d328d9..5b2376ced54a7e 100644
--- a/Modules/_testclinic.c
+++ b/Modules/_testclinic.c
@@ -1117,6 +1117,40 @@ gh_99240_double_free_impl(PyObject *module, char *a, 
char *b)
 }
 
 
+/*[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,
+};
+
+
 static PyMethodDef tester_methods[] = {
     TEST_EMPTY_FUNCTION_METHODDEF
     OBJECTS_CONVERTER_METHODDEF
@@ -1181,7 +1215,18 @@ static struct PyModuleDef _testclinic_module = {
 PyMODINIT_FUNC
 PyInit__testclinic(void)
 {
-    return PyModule_Create(&_testclinic_module);
+    PyObject *m = PyModule_Create(&_testclinic_module);
+    if (m == NULL) {
+        return NULL;
+    }
+    if (PyModule_AddType(m, &TestClass) < 0) {
+        goto error;
+    }
+    return m;
+
+error:
+    Py_DECREF(m);
+    return NULL;
 }
 
 #undef RETURN_PACKED_ARGS
diff --git a/Modules/cjkcodecs/clinic/multibytecodec.c.h 
b/Modules/cjkcodecs/clinic/multibytecodec.c.h
index 8f850aa8195ca2..009284217fac6a 100644
--- a/Modules/cjkcodecs/clinic/multibytecodec.c.h
+++ b/Modules/cjkcodecs/clinic/multibytecodec.c.h
@@ -556,7 +556,7 @@ 
_multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
 static PyObject *
 _multibytecodec_MultibyteStreamWriter_reset(MultibyteStreamWriterObject *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, "reset() takes no arguments");
         return NULL;
     }
@@ -570,4 +570,4 @@ PyDoc_STRVAR(_multibytecodec___create_codec__doc__,
 
 #define _MULTIBYTECODEC___CREATE_CODEC_METHODDEF    \
     {"__create_codec", (PyCFunction)_multibytecodec___create_codec, METH_O, 
_multibytecodec___create_codec__doc__},
-/*[clinic end generated code: output=9e4e3da5ca3c8288 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=3c007afbf48aa07a input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_curses_panel.c.h b/Modules/clinic/_curses_panel.c.h
index 31101c1011ccd6..5b9a9dfa16c2c8 100644
--- a/Modules/clinic/_curses_panel.c.h
+++ b/Modules/clinic/_curses_panel.c.h
@@ -17,7 +17,7 @@ _curses_panel_panel_bottom_impl(PyCursesPanelObject *self, 
PyTypeObject *cls);
 static PyObject *
 _curses_panel_panel_bottom(PyCursesPanelObject *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, "bottom() takes no arguments");
         return NULL;
     }
@@ -41,7 +41,7 @@ _curses_panel_panel_hide_impl(PyCursesPanelObject *self, 
PyTypeObject *cls);
 static PyObject *
 _curses_panel_panel_hide(PyCursesPanelObject *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, "hide() takes no arguments");
         return NULL;
     }
@@ -63,7 +63,7 @@ _curses_panel_panel_show_impl(PyCursesPanelObject *self, 
PyTypeObject *cls);
 static PyObject *
 _curses_panel_panel_show(PyCursesPanelObject *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, "show() takes no arguments");
         return NULL;
     }
@@ -85,7 +85,7 @@ _curses_panel_panel_top_impl(PyCursesPanelObject *self, 
PyTypeObject *cls);
 static PyObject *
 _curses_panel_panel_top(PyCursesPanelObject *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, "top() takes no arguments");
         return NULL;
     }
@@ -292,7 +292,7 @@ _curses_panel_panel_userptr_impl(PyCursesPanelObject *self,
 static PyObject *
 _curses_panel_panel_userptr(PyCursesPanelObject *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, "userptr() takes no arguments");
         return NULL;
     }
@@ -383,4 +383,4 @@ _curses_panel_update_panels(PyObject *module, PyObject 
*Py_UNUSED(ignored))
 {
     return _curses_panel_update_panels_impl(module);
 }
-/*[clinic end generated code: output=c471aed62bc31e79 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=f11fdb54e1b33334 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_dbmmodule.c.h b/Modules/clinic/_dbmmodule.c.h
index 8157716a940810..d95681032c1e5c 100644
--- a/Modules/clinic/_dbmmodule.c.h
+++ b/Modules/clinic/_dbmmodule.c.h
@@ -35,7 +35,7 @@ _dbm_dbm_keys_impl(dbmobject *self, PyTypeObject *cls);
 static PyObject *
 _dbm_dbm_keys(dbmobject *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, "keys() takes no arguments");
         return NULL;
     }
@@ -172,4 +172,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=5798278a05032d0e input=a9049054013a1b77]*/
+/*[clinic end generated code: output=57447621196fddb6 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_gdbmmodule.c.h b/Modules/clinic/_gdbmmodule.c.h
index e4cb1e9477f3ac..b04a673d7710bf 100644
--- a/Modules/clinic/_gdbmmodule.c.h
+++ b/Modules/clinic/_gdbmmodule.c.h
@@ -104,7 +104,7 @@ _gdbm_gdbm_keys_impl(gdbmobject *self, PyTypeObject *cls);
 static PyObject *
 _gdbm_gdbm_keys(gdbmobject *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, "keys() takes no arguments");
         return NULL;
     }
@@ -130,7 +130,7 @@ _gdbm_gdbm_firstkey_impl(gdbmobject *self, PyTypeObject 
*cls);
 static PyObject *
 _gdbm_gdbm_firstkey(gdbmobject *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, "firstkey() takes no arguments");
         return NULL;
     }
@@ -198,7 +198,7 @@ _gdbm_gdbm_reorganize_impl(gdbmobject *self, PyTypeObject 
*cls);
 static PyObject *
 _gdbm_gdbm_reorganize(gdbmobject *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, "reorganize() takes no arguments");
         return NULL;
     }
@@ -223,7 +223,7 @@ _gdbm_gdbm_sync_impl(gdbmobject *self, PyTypeObject *cls);
 static PyObject *
 _gdbm_gdbm_sync(gdbmobject *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, "sync() takes no arguments");
         return NULL;
     }
@@ -305,4 +305,4 @@ dbmopen(PyObject *module, PyObject *const *args, Py_ssize_t 
nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=617117d16956ac4d input=a9049054013a1b77]*/
+/*[clinic end generated code: output=8aa6f6f86554ac3c input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_lsprof.c.h b/Modules/clinic/_lsprof.c.h
index dfc003eb54774c..b3b7fda5660bfd 100644
--- a/Modules/clinic/_lsprof.c.h
+++ b/Modules/clinic/_lsprof.c.h
@@ -39,10 +39,10 @@ _lsprof_Profiler_getstats_impl(ProfilerObject *self, 
PyTypeObject *cls);
 static PyObject *
 _lsprof_Profiler_getstats(ProfilerObject *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, "getstats() takes no arguments");
         return NULL;
     }
     return _lsprof_Profiler_getstats_impl(self, cls);
 }
-/*[clinic end generated code: output=0615a53cce828f06 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=5c9d87d89863dc83 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_queuemodule.c.h b/Modules/clinic/_queuemodule.c.h
index b0b00f8199b54a..f5acf21a5de786 100644
--- a/Modules/clinic/_queuemodule.c.h
+++ b/Modules/clinic/_queuemodule.c.h
@@ -195,7 +195,7 @@ _queue_SimpleQueue_get_nowait_impl(simplequeueobject *self,
 static PyObject *
 _queue_SimpleQueue_get_nowait(simplequeueobject *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, "get_nowait() takes no arguments");
         return NULL;
     }
@@ -257,4 +257,4 @@ _queue_SimpleQueue_qsize(simplequeueobject *self, PyObject 
*Py_UNUSED(ignored))
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=88ec8033aeb7241c input=a9049054013a1b77]*/
+/*[clinic end generated code: output=edb5653095ef0eb8 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h
index c97ac1c6629607..cb5ce096d1a53a 100644
--- a/Modules/clinic/_testclinic.c.h
+++ b/Modules/clinic/_testclinic.c.h
@@ -2305,4 +2305,26 @@ gh_99240_double_free(PyObject *module, PyObject *const 
*args, Py_ssize_t nargs)
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=6b719efc1b8bd2c8 input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(_testclinic_TestClass_meth_method_no_params__doc__,
+"meth_method_no_params($self, /)\n"
+"--\n"
+"\n");
+
+#define _TESTCLINIC_TESTCLASS_METH_METHOD_NO_PARAMS_METHODDEF    \
+    {"meth_method_no_params", 
_PyCFunction_CAST(_testclinic_TestClass_meth_method_no_params), 
METH_METHOD|METH_FASTCALL|METH_KEYWORDS, 
_testclinic_TestClass_meth_method_no_params__doc__},
+
+static PyObject *
+_testclinic_TestClass_meth_method_no_params_impl(PyObject *self,
+                                                 PyTypeObject *cls);
+
+static PyObject *
+_testclinic_TestClass_meth_method_no_params(PyObject *self, PyTypeObject *cls, 
PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
+{
+    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
+        PyErr_SetString(PyExc_TypeError, "meth_method_no_params() takes no 
arguments");
+        return NULL;
+    }
+    return _testclinic_TestClass_meth_method_no_params_impl(self, cls);
+}
+/*[clinic end generated code: output=bb18445388d03bd1 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/_testmultiphase.c.h 
b/Modules/clinic/_testmultiphase.c.h
index eabaea635d50dc..551753aa2d85e6 100644
--- a/Modules/clinic/_testmultiphase.c.h
+++ b/Modules/clinic/_testmultiphase.c.h
@@ -21,7 +21,7 @@ 
_testmultiphase_StateAccessType_get_defining_module_impl(StateAccessTypeObject *
 static PyObject *
 _testmultiphase_StateAccessType_get_defining_module(StateAccessTypeObject 
*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, "get_defining_module() takes no 
arguments");
         return NULL;
     }
@@ -44,7 +44,7 @@ 
_testmultiphase_StateAccessType_getmodulebydef_bad_def_impl(StateAccessTypeObjec
 static PyObject *
 _testmultiphase_StateAccessType_getmodulebydef_bad_def(StateAccessTypeObject 
*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, "getmodulebydef_bad_def() takes no 
arguments");
         return NULL;
     }
@@ -127,10 +127,10 @@ 
_testmultiphase_StateAccessType_get_count_impl(StateAccessTypeObject *self,
 static PyObject *
 _testmultiphase_StateAccessType_get_count(StateAccessTypeObject *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, "get_count() takes no arguments");
         return NULL;
     }
     return _testmultiphase_StateAccessType_get_count_impl(self, cls);
 }
-/*[clinic end generated code: output=48739d81c3834078 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=de38f6a82927fb11 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h
index 6358ba2f81fa38..f58bd06a0c62c8 100644
--- a/Modules/clinic/arraymodule.c.h
+++ b/Modules/clinic/arraymodule.c.h
@@ -615,7 +615,7 @@ array_arrayiterator___reduce___impl(arrayiterobject *self, 
PyTypeObject *cls);
 static PyObject *
 array_arrayiterator___reduce__(arrayiterobject *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, "__reduce__() takes no arguments");
         return NULL;
     }
@@ -630,4 +630,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
 
 #define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF    \
     {"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, 
array_arrayiterator___setstate____doc__},
-/*[clinic end generated code: output=85a5fec90d9615b9 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=62cb180955450ca3 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/md5module.c.h b/Modules/clinic/md5module.c.h
index 999406ba13518c..eff2c70d6a5f11 100644
--- a/Modules/clinic/md5module.c.h
+++ b/Modules/clinic/md5module.c.h
@@ -17,7 +17,7 @@ MD5Type_copy_impl(MD5object *self, PyTypeObject *cls);
 static PyObject *
 MD5Type_copy(MD5object *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, "copy() takes no arguments");
         return NULL;
     }
@@ -119,4 +119,4 @@ _md5_md5(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs, PyObject *kw
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=e5dac1237beb2788 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=662764b684599176 input=a9049054013a1b77]*/
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index 8d5a5fecbb2287..27f12c02a80e53 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -8341,7 +8341,7 @@ os_DirEntry_is_symlink(DirEntry *self, PyTypeObject 
*defining_class, PyObject *c
     PyObject *return_value = NULL;
     int _return_value;
 
-    if (nargs) {
+    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
         PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
         goto exit;
     }
@@ -9388,4 +9388,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject 
*const *args, Py_ssize_t na
 #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
     #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
 #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
-/*[clinic end generated code: output=b649ad9a4e1f2427 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b5e292ce15f5e19e input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha1module.c.h b/Modules/clinic/sha1module.c.h
index e2338e4a1280a5..03b61aa7a39536 100644
--- a/Modules/clinic/sha1module.c.h
+++ b/Modules/clinic/sha1module.c.h
@@ -17,7 +17,7 @@ SHA1Type_copy_impl(SHA1object *self, PyTypeObject *cls);
 static PyObject *
 SHA1Type_copy(SHA1object *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, "copy() takes no arguments");
         return NULL;
     }
@@ -119,4 +119,4 @@ _sha1_sha1(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs, PyObject *
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=322d77ba0a4282fc input=a9049054013a1b77]*/
+/*[clinic end generated code: output=2a6c1586342dd24c input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha256module.c.h b/Modules/clinic/sha256module.c.h
index b94c1c548a394b..5212378f852e4b 100644
--- a/Modules/clinic/sha256module.c.h
+++ b/Modules/clinic/sha256module.c.h
@@ -17,7 +17,7 @@ SHA256Type_copy_impl(SHAobject *self, PyTypeObject *cls);
 static PyObject *
 SHA256Type_copy(SHAobject *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, "copy() takes no arguments");
         return NULL;
     }
@@ -170,4 +170,4 @@ _sha256_sha224(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs, PyObje
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=58b48051890d3fde input=a9049054013a1b77]*/
+/*[clinic end generated code: output=a4965a9b3f3b388d input=a9049054013a1b77]*/
diff --git a/Modules/clinic/sha512module.c.h b/Modules/clinic/sha512module.c.h
index b7227480c342a1..4bde6742a3faf7 100644
--- a/Modules/clinic/sha512module.c.h
+++ b/Modules/clinic/sha512module.c.h
@@ -17,7 +17,7 @@ SHA512Type_copy_impl(SHAobject *self, PyTypeObject *cls);
 static PyObject *
 SHA512Type_copy(SHAobject *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, "copy() takes no arguments");
         return NULL;
     }
@@ -170,4 +170,4 @@ _sha512_sha384(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs, PyObje
 exit:
     return return_value;
 }
-/*[clinic end generated code: output=60a0a1a28c07f391 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=b6148bd0dc27e33b input=a9049054013a1b77]*/
diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h
index ad6a7d470c5e5e..d2c9b210a938b1 100644
--- a/Modules/clinic/zlibmodule.c.h
+++ b/Modules/clinic/zlibmodule.c.h
@@ -513,7 +513,7 @@ zlib_Compress_copy_impl(compobject *self, PyTypeObject 
*cls);
 static PyObject *
 zlib_Compress_copy(compobject *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, "copy() takes no arguments");
         return NULL;
     }
@@ -538,7 +538,7 @@ zlib_Compress___copy___impl(compobject *self, PyTypeObject 
*cls);
 static PyObject *
 zlib_Compress___copy__(compobject *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, "__copy__() takes no arguments");
         return NULL;
     }
@@ -600,7 +600,7 @@ zlib_Decompress_copy_impl(compobject *self, PyTypeObject 
*cls);
 static PyObject *
 zlib_Decompress_copy(compobject *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, "copy() takes no arguments");
         return NULL;
     }
@@ -625,7 +625,7 @@ zlib_Decompress___copy___impl(compobject *self, 
PyTypeObject *cls);
 static PyObject *
 zlib_Decompress___copy__(compobject *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, "__copy__() takes no arguments");
         return NULL;
     }
@@ -855,4 +855,4 @@ zlib_crc32(PyObject *module, PyObject *const *args, 
Py_ssize_t nargs)
 #ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
     #define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
 #endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
-/*[clinic end generated code: output=757804b3ad33454f input=a9049054013a1b77]*/
+/*[clinic end generated code: output=aa12a3c71b1bc156 input=a9049054013a1b77]*/
diff --git a/Tools/c-analyzer/cpython/globals-to-fix.tsv 
b/Tools/c-analyzer/cpython/globals-to-fix.tsv
index 7e939277f1e05a..8fe861576228b3 100644
--- a/Tools/c-analyzer/cpython/globals-to-fix.tsv
+++ b/Tools/c-analyzer/cpython/globals-to-fix.tsv
@@ -686,6 +686,8 @@ Modules/signalmodule.c      -       Handlers        -
 ##################################
 # global non-objects to fix in builtin modules
 
+Modules/_testclinic.c  -       TestClass       -
+
 #-----------------------
 # initialized once
 
diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 84636b92e38a32..337ab88f7e7e93 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -799,7 +799,7 @@ def parser_body(prototype, *fields, declarations=''):
                 return_error = ('return NULL;' if default_return_converter
                                 else 'goto exit;')
                 parser_code = [normalize_snippet("""
-                    if (nargs) {{
+                    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {{
                         PyErr_SetString(PyExc_TypeError, "{name}() takes no 
arguments");
                         %s
                     }}

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to