From d6ec560997457aad1a24e5e363a877119286cda6 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Fri, 12 Apr 2024 02:52:56 +0900 Subject: [PATCH 1/4] ensure defining_class is positional only --- Lib/test/test_clinic.py | 9 +++++++++ Tools/clinic/libclinic/dsl_parser.py | 1 + 2 files changed, 10 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index e8c638ea6107822..92d832a0a48ecf2 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2508,6 +2508,15 @@ def test_state_func_docstring_only_one_param_template(self): """ self.expect_failure(block, err, lineno=7) + def test_kind_defining_class(self): + function = self.parse_function(""" + module m + m.func + cls: defining_class + """) + p = function.parameters['cls'] + self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) + class ClinicExternalTest(TestCase): maxDiff = None diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index 9e22d847c4dc90e..56c6dca3db3d1d5 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -1102,6 +1102,7 @@ def bad_node(self, node: ast.AST) -> None: fail("A 'defining_class' parameter cannot have a default value.") if self.group: fail("A 'defining_class' parameter cannot be in an optional group.") + kind = inspect.Parameter.POSITIONAL_ONLY else: fail("A 'defining_class' parameter, if specified, must either " "be the first thing in the parameter block, or come just " From ee1a93d9f471b4703180dd62a25554b1760790a8 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:56:12 +0900 Subject: [PATCH 2/4] update Modules/_sqlite/clinic/connection.c.h --- Modules/_sqlite/clinic/connection.c.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/_sqlite/clinic/connection.c.h b/Modules/_sqlite/clinic/connection.c.h index 811314b5cd8aed8..bb0a0278c629d4c 100644 --- a/Modules/_sqlite/clinic/connection.c.h +++ b/Modules/_sqlite/clinic/connection.c.h @@ -744,7 +744,7 @@ pysqlite_connection_set_authorizer(pysqlite_Connection *self, PyTypeObject *cls, PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 2 + #define NUM_KEYWORDS 1 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -837,7 +837,7 @@ pysqlite_connection_set_progress_handler(pysqlite_Connection *self, PyTypeObject PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 3 + #define NUM_KEYWORDS 2 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -925,7 +925,7 @@ pysqlite_connection_set_trace_callback(pysqlite_Connection *self, PyTypeObject * PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 2 + #define NUM_KEYWORDS 1 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -1866,4 +1866,4 @@ getconfig(pysqlite_Connection *self, PyObject *arg) #ifndef DESERIALIZE_METHODDEF #define DESERIALIZE_METHODDEF #endif /* !defined(DESERIALIZE_METHODDEF) */ -/*[clinic end generated code: output=3c6d0b748fac016f input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7d41a178b7b2b683 input=a9049054013a1b77]*/ From 3cd8b03195788959461b477358c4746272cd55e5 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:47:06 +0900 Subject: [PATCH 3/4] correct a test case --- Lib/test/test_clinic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 92d832a0a48ecf2..2e5aa91797be64f 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -2511,9 +2511,10 @@ def test_state_func_docstring_only_one_param_template(self): def test_kind_defining_class(self): function = self.parse_function(""" module m - m.func + class m.C "PyObject *" "" + m.C.meth cls: defining_class - """) + """, signatures_in_block=3, function_index=2) p = function.parameters['cls'] self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) From 9fed4f03ed88a4b44344a347a5f95ffe77e420c0 Mon Sep 17 00:00:00 2001 From: neonene <53406459+neonene@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:20:16 +0900 Subject: [PATCH 4/4] regen clinic cheksums --- Modules/clinic/_testclinic.c.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index d1e09c94f051970..6a59baa2137b75d 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -3183,7 +3183,7 @@ _testclinic_TestClass_get_defining_class_arg(PyObject *self, PyTypeObject *cls, PyObject *return_value = NULL; #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) - #define NUM_KEYWORDS 2 + #define NUM_KEYWORDS 1 static struct { PyGC_Head _this_is_not_used; PyObject_VAR_HEAD @@ -3219,4 +3219,4 @@ _testclinic_TestClass_get_defining_class_arg(PyObject *self, PyTypeObject *cls, exit: return return_value; } -/*[clinic end generated code: output=71b2a15aa86c2bcf input=a9049054013a1b77]*/ +/*[clinic end generated code: output=aa352c3a67300056 input=a9049054013a1b77]*/