]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117613: Argument Clinic: ensure that 'defining_class' params are positional-only...
authorneonene <53406459+neonene@users.noreply.github.com>
Tue, 16 Apr 2024 09:52:45 +0000 (18:52 +0900)
committerGitHub <noreply@github.com>
Tue, 16 Apr 2024 09:52:45 +0000 (09:52 +0000)
Lib/test/test_clinic.py
Modules/_sqlite/clinic/connection.c.h
Modules/clinic/_testclinic.c.h
Tools/clinic/libclinic/dsl_parser.py

index ef57aaca9597bffa71963fa96296a84e4b2aac27..43b629f59f034613e7f6a5c83fc6f103f7eabe4c 100644 (file)
@@ -2508,6 +2508,16 @@ class ClinicParserTest(TestCase):
         """
         self.expect_failure(block, err, lineno=7)
 
+    def test_kind_defining_class(self):
+        function = self.parse_function("""
+            module m
+            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)
+
 
 class ClinicExternalTest(TestCase):
     maxDiff = None
index 811314b5cd8aed8d60c3d34086ef37381c1dec0d..bb0a0278c629d4cccf489e49dd07d5380a5b7bef 100644 (file)
@@ -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 @@ exit:
 #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]*/
index d1e09c94f051970f3f0d8a6b9057dd99978e64dc..6a59baa2137b75dbc73bd593d619e2e9f6a98bc8 100644 (file)
@@ -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]*/
index 9e22d847c4dc90e27e975b2d9a0d4d6951b16da6..56c6dca3db3d1d5b4d9474e8f132897d6f79b556 100644 (file)
@@ -1102,6 +1102,7 @@ class DSLParser:
                     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 "